<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>SA实战 ·《SpringCloud Alibaba实战》快速搭建三大微服务并完成交互开发与测试 | 冰河技术</title>
    <meta name="generator" content="VuePress 1.9.7">
    <link rel="icon" href="/favicon.ico">
    <script charset="utf-8" async="async" src="/js/jquery.min.js"></script>
    <script charset="utf-8" async="async" src="/js/global.js"></script>
    <script charset="utf-8" async="async" src="/js/fingerprint2.min.js"></script>
    <script charset="utf-8" async="async" src="https://v1.cnzz.com/z_stat.php?id=1281063564&amp;web_id=1281063564"></script>
    <script charset="utf-8" async="async" src="https://s9.cnzz.com/z_stat.php?id=1281064551&amp;web_id=1281064551"></script>
    <script>
            var _hmt = _hmt || [];
            (function() {
              var hm = document.createElement("script");
              hm.src = "https://hm.baidu.com/hm.js?d091d2fd0231588b1d0f9231e24e3f5e";
              var s = document.getElementsByTagName("script")[0];
              s.parentNode.insertBefore(hm, s);
            })();
            </script>
    <meta name="description" content="包含：编程语言，开发技术，分布式，微服务，高并发，高可用，高可扩展，高可维护，JVM技术，MySQL，分布式数据库，分布式事务，云原生，大数据，云计算，渗透技术，各种面试题，面试技巧...">
    <meta property="article:modified_time" content="2022-05-23T11:30:51.000Z">
    <meta property="og:title" content="SA实战 ·《SpringCloud Alibaba实战》快速搭建三大微服务并完成交互开发与测试">
    <meta property="og:type" content="article">
    <meta property="og:url" content="/md/microservices/springcloudalibaba/2022-04-21-SA%E5%AE%9E%E6%88%98-%E5%AE%8C%E6%88%90%E4%B8%89%E5%A4%A7%E5%BE%AE%E6%9C%8D%E5%8A%A1%E7%9A%84%E6%90%AD%E5%BB%BA%E4%B8%8E%E4%BA%A4%E4%BA%92%E5%BC%80%E5%8F%91.html">
    <meta name="twitter:title" content="SA实战 ·《SpringCloud Alibaba实战》快速搭建三大微服务并完成交互开发与测试">
    <meta name="twitter:url" content="/md/microservices/springcloudalibaba/2022-04-21-SA%E5%AE%9E%E6%88%98-%E5%AE%8C%E6%88%90%E4%B8%89%E5%A4%A7%E5%BE%AE%E6%9C%8D%E5%8A%A1%E7%9A%84%E6%90%AD%E5%BB%BA%E4%B8%8E%E4%BA%A4%E4%BA%92%E5%BC%80%E5%8F%91.html">
    <meta name="twitter:card" content="summary_large_image">
    <meta name="robots" content="all">
    <meta name="author" content="冰河">
    <meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate">
    <meta http-equiv="Pragma" content="no-cache">
    <meta http-equiv="Expires" content="0">
    <meta name="keywords" content="冰河，冰河技术, 编程语言，开发技术，分布式，微服务，高并发，高可用，高可扩展，高可维护，JVM技术，MySQL，分布式数据库，分布式事务，云原生，大数据，云计算，渗透技术，各种面试题，面试技巧">
    <meta name="apple-mobile-web-app-capable" content="yes">
    
    <link rel="preload" href="/assets/css/0.styles.ab888ebb.css" as="style"><link rel="preload" href="/assets/css/styles.css?v=1653305936337" as="style"><link rel="preload" href="/assets/js/cg-styles.js?v=1653305936337" as="script"><link rel="preload" href="/assets/js/cg-app.js?v=1653305936337" as="script"><link rel="preload" href="/assets/js/cg-4.js?v=1653305936337" as="script"><link rel="preload" href="/assets/js/cg-3.js?v=1653305936337" as="script"><link rel="preload" href="/assets/js/cg-294.js?v=1653305936337" as="script"><link rel="preload" href="/assets/js/cg-5.js?v=1653305936337" as="script"><link rel="preload" href="/assets/js/cg-6.js?v=1653305936337" as="script">
    <link rel="stylesheet" href="/assets/css/0.styles.ab888ebb.css"><link rel="stylesheet" href="/assets/css/styles.css?v=1653305936337">
  </head>
  <body>
    <div id="app" data-server-rendered="true"><div class="theme-container"><header class="navbar"><div class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/" class="home-link router-link-active"><!----> <span class="site-name">冰河技术</span></a> <div class="links"><div class="search-box"><input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><div class="nav-item"><a href="/md/other/guide-to-reading.html" class="nav-link">
  导读
</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="核心技术" class="dropdown-title"><span class="title">核心技术</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><h4>
          Java核心技术
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/core/java/basics/2022-04-28-全网最全正则表达式总结.html" class="nav-link">
  Java基础
</a></li><li class="dropdown-subitem"><a href="/md/core/java/advanced/default.html" class="nav-link">
  Java进阶
</a></li><li class="dropdown-subitem"><a href="/md/core/java/senior/default.html" class="nav-link">
  Java高级
</a></li><li class="dropdown-subitem"><a href="/md/core/java/java8/2022-03-31-001-Java8有哪些新特性呢？.html" class="nav-link">
  Java8新特性
</a></li></ul></li><li class="dropdown-item"><h4>
          Spring核心技术
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/core/spring/ioc/2022-04-04-001-聊聊Spring注解驱动开发那些事儿.html" class="nav-link">
  IOC核心技术
</a></li><li class="dropdown-subitem"><a href="/md/core/spring/aop/default.html" class="nav-link">
  AOP核心技术
</a></li></ul></li><li class="dropdown-item"><h4>
          JVM核心技术
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/core/jvm/2022-04-18-001-JVM调优的几种场景.html" class="nav-link">
  JVM调优技术
</a></li></ul></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="性能调优" class="dropdown-title"><span class="title">性能调优</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/md/performance/jvm/default.html" class="nav-link">
  JVM性能调优
</a></li><li class="dropdown-item"><!----> <a href="/md/performance/tomcat/default.html" class="nav-link">
  Tomcat性能调优
</a></li><li class="dropdown-item"><!----> <a href="/md/performance/mysql/default.html" class="nav-link">
  MySQL性能调优
</a></li><li class="dropdown-item"><!----> <a href="/md/performance/system/default.html" class="nav-link">
  操作系统性能调优
</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="并发编程" class="dropdown-title"><span class="title">并发编程</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/md/concurrent/bottom/default.html" class="nav-link">
  底层技术
</a></li><li class="dropdown-item"><!----> <a href="/md/concurrent/source/2020-03-30-001-一文搞懂线程与多线程.html" class="nav-link">
  源码分析
</a></li><li class="dropdown-item"><!----> <a href="/md/concurrent/basics/2020-03-30-001-明明中断了线程，却为何不起作用呢？.html" class="nav-link">
  基础案例
</a></li><li class="dropdown-item"><!----> <a href="/md/concurrent/ActualCombat/default.html" class="nav-link">
  实战案例
</a></li><li class="dropdown-item"><!----> <a href="/md/concurrent/interview/default.html" class="nav-link">
  面试
</a></li><li class="dropdown-item"><!----> <a href="/md/concurrent/framework/default.html" class="nav-link">
  系统架构
</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="框架源码" class="dropdown-title"><span class="title">框架源码</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/md/frame/spring/default.html" class="nav-link">
  Spring源码
</a></li><li class="dropdown-item"><!----> <a href="/md/frame/springmvc/default.html" class="nav-link">
  SpringMVC源码
</a></li><li class="dropdown-item"><!----> <a href="/md/frame/mybatis/default.html" class="nav-link">
  MyBatis源码
</a></li><li class="dropdown-item"><!----> <a href="/md/frame/dubbo/default.html" class="nav-link">
  Dubbo源码
</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="分布式" class="dropdown-title"><span class="title">分布式</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><h4>
          缓存技术
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/distributed/cache/default.html" class="nav-link">
  Redis
</a></li></ul></li><li class="dropdown-item"><h4>
          服务注册发现
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/distributed/zookeeper/default.html" class="nav-link">
  Zookeeper
</a></li></ul></li><li class="dropdown-item"><h4>
          消息中间件
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/distributed/mq/rabbitmq/default.html" class="nav-link">
  RabbitMQ
</a></li><li class="dropdown-subitem"><a href="/md/distributed/mq/rocketmq/default.html" class="nav-link">
  RocketMQ
</a></li><li class="dropdown-subitem"><a href="/md/distributed/mq/kafka/default.html" class="nav-link">
  Kafka
</a></li></ul></li><li class="dropdown-item"><h4>
          网络通信
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/distributed/netty/default.html" class="nav-link">
  Netty
</a></li></ul></li><li class="dropdown-item"><h4>
          远程调用
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/distributed/dubbo/default.html" class="nav-link">
  Dubbo
</a></li></ul></li><li class="dropdown-item"><h4>
          数据库
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/distributed/mongodb/default.html" class="nav-link">
  MongoDB
</a></li></ul></li><li class="dropdown-item"><h4>
          搜索引擎
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/distributed/es/default.html" class="nav-link">
  ElasticSearch
</a></li></ul></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="微服务" class="dropdown-title"><span class="title">微服务</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/md/microservices/springboot/default.html" class="nav-link">
  SpringBoot
</a></li><li class="dropdown-item"><!----> <a href="/md/microservices/springcloudalibaba/2022-04-02-SpringCloudAlibaba专栏开篇.html" class="nav-link">
  SpringCloudAlibaba
</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="中间件" class="dropdown-title"><span class="title">中间件</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/md/middleware/bytecode/2022-04-11-001-工作多年的你依然重复做着CRUD-是否接触过这种技术.html" class="nav-link">
  字节码编程
</a></li><li class="dropdown-item"><!----> <a href="/md/middleware/threadpool/default.html" class="nav-link">
  手写线程池
</a></li><li class="dropdown-item"><!----> <a href="/md/middleware/limiter/default.html" class="nav-link">
  分布式限流
</a></li><li class="dropdown-item"><!----> <a href="/md/middleware/independent/default.html" class="nav-link">
  开源项目
</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="项目实战" class="dropdown-title"><span class="title">项目实战</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/md/microservices/springcloudalibaba/2022-04-02-SpringCloudAlibaba专栏开篇.html" class="nav-link">
  SpringCloud Alibaba实战
</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="渗透技术" class="dropdown-title"><span class="title">渗透技术</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/md/hack/environment/2022-04-17-001-安装Kali系统.html" class="nav-link">
  基础环境篇
</a></li><li class="dropdown-item"><!----> <a href="/md/hack/tools/2022-04-17-001-使用Easy-Creds工具攻击无线网络.html" class="nav-link">
  渗透工具篇
</a></li><li class="dropdown-item"><!----> <a href="/md/hack/horse/2022-05-02-001-各种一句话木马大全.html" class="nav-link">
  木马篇
</a></li><li class="dropdown-item"><!----> <a href="/md/hack/sql/2022-05-02-001-sqli-labs-master下载与安装.html" class="nav-link">
  SQL注入篇
</a></li><li class="dropdown-item"><!----> <a href="/md/hack/shell/2022-05-02-001-各种解析漏洞拿shell.html" class="nav-link">
  漏洞拿Shell篇
</a></li><li class="dropdown-item"><!----> <a href="/md/hack/crack/2022-05-02-001-使用rarcrack暴力破解RAR-ZIP-7Z压缩包.html" class="nav-link">
  暴力破解篇
</a></li><li class="dropdown-item"><!----> <a href="/md/hack/bash/2022-05-02-001-3389脚本开启代码(vbs版).html" class="nav-link">
  渗透脚本篇
</a></li><li class="dropdown-item"><!----> <a href="/md/hack/raising/2022-05-02-001-数据库提权.html" class="nav-link">
  数据与系统提权篇
</a></li><li class="dropdown-item"><!----> <a href="/md/hack/client/2022-05-02-001-浏览器渗透.html" class="nav-link">
  客户端渗透篇
</a></li><li class="dropdown-item"><!----> <a href="/md/hack/sociology/2022-05-02-001-Metasploit之社会工程学工具包.html" class="nav-link">
  社会工程学
</a></li><li class="dropdown-item"><!----> <a href="/md/hack/question/2022-05-02-001-HTTP错误4031禁止访问-执行访问被拒绝.html" class="nav-link">
  问题记录篇
</a></li></ul></div></div><div class="nav-item"><a href="/md/interview/2022-04-18-001-面试必问-聊聊JVM性能调优.html" class="nav-link">
  面试必问系列
</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="📚PDF" class="dropdown-title"><span class="title">📚PDF</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><h4>
          出版图书
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/knowledge/book/2022-03-29-深入理解分布式事务.html" class="nav-link">
  《深入理解分布式事务：原理与实战》
</a></li><li class="dropdown-subitem"><a href="/md/knowledge/book/2022-03-29-MySQL技术大全.html" class="nav-link">
  《MySQL技术大全：开发、优化与运维实战》
</a></li><li class="dropdown-subitem"><a href="/md/knowledge/book/2022-03-29-海量数据处理与大数据技术实战.html" class="nav-link">
  《海量数据处理与大数据技术实战》
</a></li></ul></li><li class="dropdown-item"><h4>
          电子书籍
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/knowledge/pdf/2022-03-30-《冰河的渗透实战笔记》电子书，442页，37万字，正式发布.html" class="nav-link">
  冰河的渗透实战笔记
</a></li></ul></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="关于" class="dropdown-title"><span class="title">关于</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/md/about/me/about-me.html" class="nav-link">
  关于自己
</a></li><li class="dropdown-item"><!----> <a href="/md/about/study/default.html" class="nav-link">
  关于学习
</a></li><li class="dropdown-item"><!----> <a href="/md/about/job/default.html" class="nav-link">
  关于职场
</a></li></ul></div></div><div class="nav-item"><a href="https://space.bilibili.com/517638832" target="_blank" rel="noopener noreferrer" class="nav-link external">
  B站
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></div><div class="nav-item"><a href="https://github.com/binghe001/BingheGuide" target="_blank" rel="noopener noreferrer" class="nav-link external">
  Github
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></div> <!----></nav></div></header> <div class="sidebar-mask"></div> <aside class="sidebar"><nav class="nav-links"><div class="nav-item"><a href="/md/other/guide-to-reading.html" class="nav-link">
  导读
</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="核心技术" class="dropdown-title"><span class="title">核心技术</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><h4>
          Java核心技术
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/core/java/basics/2022-04-28-全网最全正则表达式总结.html" class="nav-link">
  Java基础
</a></li><li class="dropdown-subitem"><a href="/md/core/java/advanced/default.html" class="nav-link">
  Java进阶
</a></li><li class="dropdown-subitem"><a href="/md/core/java/senior/default.html" class="nav-link">
  Java高级
</a></li><li class="dropdown-subitem"><a href="/md/core/java/java8/2022-03-31-001-Java8有哪些新特性呢？.html" class="nav-link">
  Java8新特性
</a></li></ul></li><li class="dropdown-item"><h4>
          Spring核心技术
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/core/spring/ioc/2022-04-04-001-聊聊Spring注解驱动开发那些事儿.html" class="nav-link">
  IOC核心技术
</a></li><li class="dropdown-subitem"><a href="/md/core/spring/aop/default.html" class="nav-link">
  AOP核心技术
</a></li></ul></li><li class="dropdown-item"><h4>
          JVM核心技术
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/core/jvm/2022-04-18-001-JVM调优的几种场景.html" class="nav-link">
  JVM调优技术
</a></li></ul></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="性能调优" class="dropdown-title"><span class="title">性能调优</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/md/performance/jvm/default.html" class="nav-link">
  JVM性能调优
</a></li><li class="dropdown-item"><!----> <a href="/md/performance/tomcat/default.html" class="nav-link">
  Tomcat性能调优
</a></li><li class="dropdown-item"><!----> <a href="/md/performance/mysql/default.html" class="nav-link">
  MySQL性能调优
</a></li><li class="dropdown-item"><!----> <a href="/md/performance/system/default.html" class="nav-link">
  操作系统性能调优
</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="并发编程" class="dropdown-title"><span class="title">并发编程</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/md/concurrent/bottom/default.html" class="nav-link">
  底层技术
</a></li><li class="dropdown-item"><!----> <a href="/md/concurrent/source/2020-03-30-001-一文搞懂线程与多线程.html" class="nav-link">
  源码分析
</a></li><li class="dropdown-item"><!----> <a href="/md/concurrent/basics/2020-03-30-001-明明中断了线程，却为何不起作用呢？.html" class="nav-link">
  基础案例
</a></li><li class="dropdown-item"><!----> <a href="/md/concurrent/ActualCombat/default.html" class="nav-link">
  实战案例
</a></li><li class="dropdown-item"><!----> <a href="/md/concurrent/interview/default.html" class="nav-link">
  面试
</a></li><li class="dropdown-item"><!----> <a href="/md/concurrent/framework/default.html" class="nav-link">
  系统架构
</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="框架源码" class="dropdown-title"><span class="title">框架源码</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/md/frame/spring/default.html" class="nav-link">
  Spring源码
</a></li><li class="dropdown-item"><!----> <a href="/md/frame/springmvc/default.html" class="nav-link">
  SpringMVC源码
</a></li><li class="dropdown-item"><!----> <a href="/md/frame/mybatis/default.html" class="nav-link">
  MyBatis源码
</a></li><li class="dropdown-item"><!----> <a href="/md/frame/dubbo/default.html" class="nav-link">
  Dubbo源码
</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="分布式" class="dropdown-title"><span class="title">分布式</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><h4>
          缓存技术
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/distributed/cache/default.html" class="nav-link">
  Redis
</a></li></ul></li><li class="dropdown-item"><h4>
          服务注册发现
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/distributed/zookeeper/default.html" class="nav-link">
  Zookeeper
</a></li></ul></li><li class="dropdown-item"><h4>
          消息中间件
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/distributed/mq/rabbitmq/default.html" class="nav-link">
  RabbitMQ
</a></li><li class="dropdown-subitem"><a href="/md/distributed/mq/rocketmq/default.html" class="nav-link">
  RocketMQ
</a></li><li class="dropdown-subitem"><a href="/md/distributed/mq/kafka/default.html" class="nav-link">
  Kafka
</a></li></ul></li><li class="dropdown-item"><h4>
          网络通信
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/distributed/netty/default.html" class="nav-link">
  Netty
</a></li></ul></li><li class="dropdown-item"><h4>
          远程调用
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/distributed/dubbo/default.html" class="nav-link">
  Dubbo
</a></li></ul></li><li class="dropdown-item"><h4>
          数据库
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/distributed/mongodb/default.html" class="nav-link">
  MongoDB
</a></li></ul></li><li class="dropdown-item"><h4>
          搜索引擎
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/distributed/es/default.html" class="nav-link">
  ElasticSearch
</a></li></ul></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="微服务" class="dropdown-title"><span class="title">微服务</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/md/microservices/springboot/default.html" class="nav-link">
  SpringBoot
</a></li><li class="dropdown-item"><!----> <a href="/md/microservices/springcloudalibaba/2022-04-02-SpringCloudAlibaba专栏开篇.html" class="nav-link">
  SpringCloudAlibaba
</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="中间件" class="dropdown-title"><span class="title">中间件</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/md/middleware/bytecode/2022-04-11-001-工作多年的你依然重复做着CRUD-是否接触过这种技术.html" class="nav-link">
  字节码编程
</a></li><li class="dropdown-item"><!----> <a href="/md/middleware/threadpool/default.html" class="nav-link">
  手写线程池
</a></li><li class="dropdown-item"><!----> <a href="/md/middleware/limiter/default.html" class="nav-link">
  分布式限流
</a></li><li class="dropdown-item"><!----> <a href="/md/middleware/independent/default.html" class="nav-link">
  开源项目
</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="项目实战" class="dropdown-title"><span class="title">项目实战</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/md/microservices/springcloudalibaba/2022-04-02-SpringCloudAlibaba专栏开篇.html" class="nav-link">
  SpringCloud Alibaba实战
</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="渗透技术" class="dropdown-title"><span class="title">渗透技术</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/md/hack/environment/2022-04-17-001-安装Kali系统.html" class="nav-link">
  基础环境篇
</a></li><li class="dropdown-item"><!----> <a href="/md/hack/tools/2022-04-17-001-使用Easy-Creds工具攻击无线网络.html" class="nav-link">
  渗透工具篇
</a></li><li class="dropdown-item"><!----> <a href="/md/hack/horse/2022-05-02-001-各种一句话木马大全.html" class="nav-link">
  木马篇
</a></li><li class="dropdown-item"><!----> <a href="/md/hack/sql/2022-05-02-001-sqli-labs-master下载与安装.html" class="nav-link">
  SQL注入篇
</a></li><li class="dropdown-item"><!----> <a href="/md/hack/shell/2022-05-02-001-各种解析漏洞拿shell.html" class="nav-link">
  漏洞拿Shell篇
</a></li><li class="dropdown-item"><!----> <a href="/md/hack/crack/2022-05-02-001-使用rarcrack暴力破解RAR-ZIP-7Z压缩包.html" class="nav-link">
  暴力破解篇
</a></li><li class="dropdown-item"><!----> <a href="/md/hack/bash/2022-05-02-001-3389脚本开启代码(vbs版).html" class="nav-link">
  渗透脚本篇
</a></li><li class="dropdown-item"><!----> <a href="/md/hack/raising/2022-05-02-001-数据库提权.html" class="nav-link">
  数据与系统提权篇
</a></li><li class="dropdown-item"><!----> <a href="/md/hack/client/2022-05-02-001-浏览器渗透.html" class="nav-link">
  客户端渗透篇
</a></li><li class="dropdown-item"><!----> <a href="/md/hack/sociology/2022-05-02-001-Metasploit之社会工程学工具包.html" class="nav-link">
  社会工程学
</a></li><li class="dropdown-item"><!----> <a href="/md/hack/question/2022-05-02-001-HTTP错误4031禁止访问-执行访问被拒绝.html" class="nav-link">
  问题记录篇
</a></li></ul></div></div><div class="nav-item"><a href="/md/interview/2022-04-18-001-面试必问-聊聊JVM性能调优.html" class="nav-link">
  面试必问系列
</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="📚PDF" class="dropdown-title"><span class="title">📚PDF</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><h4>
          出版图书
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/knowledge/book/2022-03-29-深入理解分布式事务.html" class="nav-link">
  《深入理解分布式事务：原理与实战》
</a></li><li class="dropdown-subitem"><a href="/md/knowledge/book/2022-03-29-MySQL技术大全.html" class="nav-link">
  《MySQL技术大全：开发、优化与运维实战》
</a></li><li class="dropdown-subitem"><a href="/md/knowledge/book/2022-03-29-海量数据处理与大数据技术实战.html" class="nav-link">
  《海量数据处理与大数据技术实战》
</a></li></ul></li><li class="dropdown-item"><h4>
          电子书籍
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/knowledge/pdf/2022-03-30-《冰河的渗透实战笔记》电子书，442页，37万字，正式发布.html" class="nav-link">
  冰河的渗透实战笔记
</a></li></ul></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="关于" class="dropdown-title"><span class="title">关于</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/md/about/me/about-me.html" class="nav-link">
  关于自己
</a></li><li class="dropdown-item"><!----> <a href="/md/about/study/default.html" class="nav-link">
  关于学习
</a></li><li class="dropdown-item"><!----> <a href="/md/about/job/default.html" class="nav-link">
  关于职场
</a></li></ul></div></div><div class="nav-item"><a href="https://space.bilibili.com/517638832" target="_blank" rel="noopener noreferrer" class="nav-link external">
  B站
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></div><div class="nav-item"><a href="https://github.com/binghe001/BingheGuide" target="_blank" rel="noopener noreferrer" class="nav-link external">
  Github
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></div> <!----></nav>  <ul class="sidebar-links"><li><section class="sidebar-group depth-0"><p class="sidebar-heading"><span>SpringBoot</span> <!----></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/md/microservices/springboot/default.html" class="sidebar-link">关于我</a></li></ul></section></li><li><section class="sidebar-group depth-0"><p class="sidebar-heading open"><span>SpringCloudAlibaba</span> <!----></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/md/microservices/springcloudalibaba/2022-04-02-SpringCloudAlibaba专栏开篇.html" class="sidebar-link">SA实战 ·《SpringCloud Alibaba实战》专栏开篇啦</a></li><li><a href="/md/microservices/springcloudalibaba/2022-04-04-SA实战·第一篇-专栏设计.html" class="sidebar-link">SA实战 · 《SpringCloud Alibaba实战》专栏设计</a></li><li><a href="/md/microservices/springcloudalibaba/2022-04-09-SA实战-微服务介绍.html" class="sidebar-link">SA实战 ·《SpringCloud Alibaba实战》微服务介绍</a></li><li><a href="/md/microservices/springcloudalibaba/2022-04-13-SA实战·项目说明-流程设计-技术选型-模块划分.html" class="sidebar-link">SA实战 ·《SpringCloud Alibaba实战》项目说明、流程设计、技术选型与模块划分</a></li><li><a href="/md/microservices/springcloudalibaba/2022-04-18-SA实战-开撸-完成通用模块的开发.html" class="sidebar-link">SA实战 ·《SpringCloud Alibaba实战》开撸：完成通用模块的开发</a></li><li><a href="/md/microservices/springcloudalibaba/2022-04-21-SA实战-完成三大微服务的搭建与交互开发.html" class="active sidebar-link">SA实战 ·《SpringCloud Alibaba实战》快速搭建三大微服务并完成交互开发与测试</a></li><li><a href="/md/microservices/springcloudalibaba/2022-04-25-SA实战-服务治理-实现服务的注册与发现.html" class="sidebar-link">SA实战 ·《SpringCloud Alibaba实战》服务治理：实现服务的自动注册与发现</a></li><li><a href="/md/microservices/springcloudalibaba/2022-04-27-SA实战-第8章-服务治理-实现服务调用的负载均衡.html" class="sidebar-link">SA实战 ·《SpringCloud Alibaba实战》第8章-服务治理：实现服务调用的负载均衡</a></li><li><a href="/md/microservices/springcloudalibaba/2022-04-28-SA实战-第9章-服务容错-服务雪崩与容错方案.html" class="sidebar-link">SA实战 ·《SpringCloud Alibaba实战》第9章-服务容错：服务雪崩与容错方案</a></li><li><a href="/md/microservices/springcloudalibaba/2022-05-03-SA实战-第10章-服务容错-Fegin整合Sentinel.html" class="sidebar-link">SA实战 ·《SpringCloud Alibaba实战》第10章-服务容错：项目整合Sentinel实现限流与容错</a></li><li><a href="/md/microservices/springcloudalibaba/2022-05-05-SA实战-第11章-服务容错加餐-Sentinel核心技术与配置规则.html" class="sidebar-link">SA实战 ·《SpringCloud Alibaba实战》第11章-服务容错加餐：Sentinel核心技术与配置规则（最全使用教程）</a></li><li><a href="/md/microservices/springcloudalibaba/2022-05-08-SA实战-第12章-服务网关-网关概述与核心架构.html" class="sidebar-link">SA实战 ·《SpringCloud Alibaba实战》第12章-服务网关：网关概述与核心架构</a></li><li><a href="/md/microservices/springcloudalibaba/2022-05-08-SA实战-第13章-服务网关-项目整合SpringCloudGateway.html" class="sidebar-link">SA实战 ·《SpringCloud Alibaba实战》第13章-服务网关：项目整合SpringCloud Gateway网关</a></li><li><a href="/md/microservices/springcloudalibaba/2022-05-10-SA实战-第14章-服务网关-SpringCloudGateway核心技术.html" class="sidebar-link">SA实战 ·《SpringCloud Alibaba实战》第14章-服务网关加餐：SpringCloud Gateway核心技术</a></li><li><a href="/md/microservices/springcloudalibaba/2022-05-11-SA实战-第15章-链路追踪-核心原理与解决方案.html" class="sidebar-link">SA实战 ·《SpringCloud Alibaba实战》第15章-链路追踪：核心原理与解决方案</a></li><li><a href="/md/microservices/springcloudalibaba/2022-05-12-SA实战-第16章-链路追踪-项目整合Sleuth实现链路追踪.html" class="sidebar-link">SA实战 ·《SpringCloud Alibaba实战》第16章-链路追踪：项目整合Sleuth实现链路追踪</a></li><li><a href="/md/microservices/springcloudalibaba/2022-05-13-SA实战-第17章-链路追踪-Sleuth整合ZipKin.html" class="sidebar-link">SA实战 ·《SpringCloud Alibaba实战》第17章-链路追踪：Sleuth整合ZipKin</a></li><li><a href="/md/microservices/springcloudalibaba/2022-05-17-SA实战-第18章-消息服务-MQ使用场景与选型对比.html" class="sidebar-link">SA实战 ·《SpringCloud Alibaba实战》第18章-消息服务：MQ使用场景与选型对比</a></li><li><a href="/md/microservices/springcloudalibaba/2022-05-18-SA实战-第19章-消息服务-项目整合RocketMQ.html" class="sidebar-link">SA实战 ·《SpringCloud Alibaba实战》第19章-消息服务：项目整合RocketMQ</a></li><li><a href="/md/microservices/springcloudalibaba/2022-05-20-SA实战-第20章-消息服务-RocketMQ核心技术.html" class="sidebar-link">SA实战 ·《SpringCloud Alibaba实战》第20章-消息服务：RocketMQ核心技术</a></li><li><a href="/md/microservices/springcloudalibaba/2022-05-21-SA实战-第21章-服务配置-服务配置介绍与Nacos核心概念.html" class="sidebar-link">SA实战 ·《SpringCloud Alibaba实战》第21章-服务配置：服务配置介绍与Nacos核心概念</a></li></ul></section></li></ul> </aside> <div><main class="page"> <div class="theme-default-content content__default"><h1 id="sa实战-·《springcloud-alibaba实战》快速搭建三大微服务并完成交互开发与测试"><a href="#sa实战-·《springcloud-alibaba实战》快速搭建三大微服务并完成交互开发与测试" class="header-anchor">#</a> SA实战 ·《SpringCloud Alibaba实战》快速搭建三大微服务并完成交互开发与测试</h1> <p><strong>大家好，我是冰河~~</strong></p> <p>在《<a href="https://mp.weixin.qq.com/mp/appmsgalbum?__biz=Mzg4MjU0OTM1OA==&amp;action=getalbum&amp;album_id=2337104419664084992&amp;scene=173&amp;from_msgid=2247500214&amp;from_itemidx=1&amp;count=3&amp;nolastread=1#wechat_redirect" target="_blank" rel="noopener noreferrer">SpringCloud Alibaba实战<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a>》专栏中前面的文章，我们为开发用户微服务、商品微服务和订单微服务做了充分的准备。今天，我们就一起正式开撸三大微服务的核心业务。</p> <h2 id="文章结构"><a href="#文章结构" class="header-anchor">#</a> 文章结构</h2> <p>本文有点长，文章的总体结构如下图所示。</p> <p><img alt="sa-2022-04-21-008" data-src="https://binghe001.github.io/assets/images/microservices/springcloudalibaba/sa-2022-04-21-008.png" loading="lazy" class="lazy"></p> <h2 id="项目概述"><a href="#项目概述" class="header-anchor">#</a> 项目概述</h2> <p>为了便于大家理解和跟上开发的进度，今天我们先使用SpringBoot快速搭建三大微服务，并基于SpringBoot完成三大微服务之间的交互。在后续的文章中，我们会陆续加入SpringCloud Alibaba的各种组件进行优化。</p> <h3 id="整体交互流程"><a href="#整体交互流程" class="header-anchor">#</a> 整体交互流程</h3> <p>在正式开撸源码之前，我们还是先来看下用户微服务、商品微服务和订单微服务的交互流程吧，也好让小伙伴们能够大体上了解系统的交互流程。</p> <p><img alt="sa-2022-04-21-001" data-src="https://binghe001.github.io/assets/images/microservices/springcloudalibaba/sa-2022-04-21-001.png" loading="lazy" class="lazy"></p> <p>上图中比较清晰的描述了三大微服务的交互流程，这里，我就不再赘述了。如果有个别小伙伴对服务的交互流程存在疑问或者问题，<strong>可以到【冰河技术】知识星球中向我提问，文末有星球优惠券。</strong></p> <h3 id="服务规划"><a href="#服务规划" class="header-anchor">#</a> 服务规划</h3> <p>对于用户微服务、商品微服务和订单微服务来说，每个服务占用的端口和访问的基础路径是不同的，这里就将每个服务占用的端口和访问的基础路径整理成下表所示。</p> <table><thead><tr><th>服务名称</th> <th>项目名称</th> <th>占用端口</th> <th>访问的基础路径</th> <th>备注</th></tr></thead> <tbody><tr><td>用户微服务</td> <td>shop-user</td> <td>8060</td> <td>/user</td> <td>提供用户信息的增删改查服务</td></tr> <tr><td>商品微服务</td> <td>shop-product</td> <td>8070</td> <td>/product</td> <td>提供商品信息的增删改查服务</td></tr> <tr><td>订单微服务</td> <td>shop-order</td> <td>8080</td> <td>/order</td> <td>提供订单信息的增删改查服务</td></tr></tbody></table> <p>好了，接下来，我们就基于SpringBoot正式开撸三大微服务。</p> <h2 id="用户微服务"><a href="#用户微服务" class="header-anchor">#</a> 用户微服务</h2> <p>用户微服务主要用来提供对于用户基础信息的增删改查操作，用户执行下单操作时，会从用户微服务中查询用户的基本信息。用户微服务的总体结构如下图所示。</p> <p><img alt="sa-2022-04-21-002" data-src="https://binghe001.github.io/assets/images/microservices/springcloudalibaba/sa-2022-04-21-002.png" loading="lazy" class="lazy"></p> <h3 id="搭建项目"><a href="#搭建项目" class="header-anchor">#</a> 搭建项目</h3> <p>创建名称为shop-user的Maven项目，由于我们在前面的文章中，已经完成了对项目整体结构的搭建，所以，在shop-user的pom.xml文件里添加如下依赖即可。</p> <div class="language-xml line-numbers-mode"><pre class="language-xml"><code><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>dependencies</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>dependency</span><span class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>groupId</span><span class="token punctuation">&gt;</span></span>io.binghe.shop<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>groupId</span><span class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>artifactId</span><span class="token punctuation">&gt;</span></span>shop-bean<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>artifactId</span><span class="token punctuation">&gt;</span></span>
        <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>version</span><span class="token punctuation">&gt;</span></span>1.0.0-SNAPSHOT<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>version</span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>dependency</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>dependencies</span><span class="token punctuation">&gt;</span></span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br></div></div><p>接下来，在项目的resources目录下创建application.yml文件，并在application.yml文件中添加如下配置。</p> <div class="language-yaml line-numbers-mode"><pre class="language-yaml"><code><span class="token key atrule">server</span><span class="token punctuation">:</span>
  <span class="token key atrule">port</span><span class="token punctuation">:</span> <span class="token number">8060</span>
  <span class="token key atrule">servlet</span><span class="token punctuation">:</span>
    <span class="token key atrule">context-path</span><span class="token punctuation">:</span> /user
<span class="token key atrule">spring</span><span class="token punctuation">:</span>
  <span class="token key atrule">application</span><span class="token punctuation">:</span>
    <span class="token key atrule">name</span><span class="token punctuation">:</span> server<span class="token punctuation">-</span>user
  <span class="token key atrule">datasource</span><span class="token punctuation">:</span>
    <span class="token key atrule">driver-class-name</span><span class="token punctuation">:</span> com.mysql.cj.jdbc.Driver
    <span class="token key atrule">url</span><span class="token punctuation">:</span> jdbc<span class="token punctuation">:</span>mysql<span class="token punctuation">:</span>//localhost<span class="token punctuation">:</span>3306/shop<span class="token punctuation">?</span>useSSL=false<span class="token important">&amp;useUnicode=true&amp;characterEncoding=utf-8&amp;allowMultiQueries=true&amp;serverTimezone=Asia/Shanghai</span>
    <span class="token key atrule">username</span><span class="token punctuation">:</span> root
    <span class="token key atrule">password</span><span class="token punctuation">:</span> root
    <span class="token key atrule">platform</span><span class="token punctuation">:</span> mysql
    <span class="token key atrule">type</span><span class="token punctuation">:</span> com.alibaba.druid.pool.DruidDataSource
    <span class="token comment"># 下面为连接池的补充设置，应用到上面所有数据源中</span>
    <span class="token comment"># 初始化大小，最小，最大</span>
    <span class="token key atrule">initialSize</span><span class="token punctuation">:</span> <span class="token number">10</span>
    <span class="token key atrule">minIdle</span><span class="token punctuation">:</span> <span class="token number">5</span>
    <span class="token key atrule">maxActive</span><span class="token punctuation">:</span> <span class="token number">20</span>
    <span class="token comment"># 配置获取连接等待超时的时间</span>
    <span class="token key atrule">maxWait</span><span class="token punctuation">:</span> <span class="token number">60000</span>
    <span class="token comment"># 配置间隔多久才进行一次检测，检测需要关闭的空闲连接，单位是毫秒</span>
    <span class="token key atrule">timeBetweenEvictionRunsMillis</span><span class="token punctuation">:</span> <span class="token number">3600000</span>
    <span class="token comment"># 配置一个连接在池中最小生存的时间，单位是毫秒</span>
    <span class="token key atrule">minEvictableIdleTimeMillis</span><span class="token punctuation">:</span> <span class="token number">3600000</span>
    <span class="token key atrule">validationQuery</span><span class="token punctuation">:</span> select 1 from dual
    <span class="token key atrule">testWhileIdle</span><span class="token punctuation">:</span> <span class="token boolean important">true</span>
    <span class="token key atrule">testOnBorrow</span><span class="token punctuation">:</span> <span class="token boolean important">false</span>
    <span class="token key atrule">testOnReturn</span><span class="token punctuation">:</span> <span class="token boolean important">false</span>
    <span class="token comment"># 打开PSCache，并且指定每个连接上PSCache的大小</span>
    <span class="token key atrule">poolPreparedStatements</span><span class="token punctuation">:</span> <span class="token boolean important">true</span>
    <span class="token key atrule">maxPoolPreparedStatementPerConnectionSize</span><span class="token punctuation">:</span> <span class="token number">20</span>
    <span class="token key atrule">maxOpenPreparedStatements</span><span class="token punctuation">:</span> <span class="token number">20</span>
    <span class="token comment"># 配置监控统计拦截的filters，去掉后监控界面sql无法统计，'wall'用于防火墙</span>
    <span class="token key atrule">filters</span><span class="token punctuation">:</span> stat

  <span class="token key atrule">http</span><span class="token punctuation">:</span>
    <span class="token key atrule">encoding</span><span class="token punctuation">:</span>
      <span class="token key atrule">enabled</span><span class="token punctuation">:</span> <span class="token boolean important">true</span>
      <span class="token key atrule">charset</span><span class="token punctuation">:</span> UTF<span class="token punctuation">-</span><span class="token number">8</span>
      <span class="token key atrule">force</span><span class="token punctuation">:</span> <span class="token boolean important">true</span>

  <span class="token key atrule">mybatis-plus</span><span class="token punctuation">:</span>
    <span class="token key atrule">global-config</span><span class="token punctuation">:</span>
      <span class="token key atrule">db-config</span><span class="token punctuation">:</span>
        <span class="token key atrule">id-type</span><span class="token punctuation">:</span> auto
        <span class="token key atrule">field-strategy</span><span class="token punctuation">:</span> not<span class="token punctuation">-</span>empty
        <span class="token key atrule">table-underline</span><span class="token punctuation">:</span> <span class="token boolean important">true</span>
        <span class="token key atrule">db-type</span><span class="token punctuation">:</span> oracle
        <span class="token key atrule">logic-delete-value</span><span class="token punctuation">:</span> <span class="token number">1</span>
        <span class="token key atrule">logic-not-delete-value</span><span class="token punctuation">:</span> <span class="token number">0</span>
    <span class="token key atrule">mapper-locations</span><span class="token punctuation">:</span> classpath<span class="token punctuation">:</span>/mapper/<span class="token important">*.xml</span>
    <span class="token key atrule">configuration</span><span class="token punctuation">:</span>
      <span class="token key atrule">jdbc-type-for-null</span><span class="token punctuation">:</span> <span class="token string">'null'</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br><span class="line-number">26</span><br><span class="line-number">27</span><br><span class="line-number">28</span><br><span class="line-number">29</span><br><span class="line-number">30</span><br><span class="line-number">31</span><br><span class="line-number">32</span><br><span class="line-number">33</span><br><span class="line-number">34</span><br><span class="line-number">35</span><br><span class="line-number">36</span><br><span class="line-number">37</span><br><span class="line-number">38</span><br><span class="line-number">39</span><br><span class="line-number">40</span><br><span class="line-number">41</span><br><span class="line-number">42</span><br><span class="line-number">43</span><br><span class="line-number">44</span><br><span class="line-number">45</span><br><span class="line-number">46</span><br><span class="line-number">47</span><br><span class="line-number">48</span><br><span class="line-number">49</span><br><span class="line-number">50</span><br><span class="line-number">51</span><br><span class="line-number">52</span><br><span class="line-number">53</span><br><span class="line-number">54</span><br></div></div><p>从配置文件中，我们也可以看出，用户微服务启动后监听的端口为8060，基础的访问路径为/user，应用的名称为server-user，使用的数据库为MySQL，使用的数据库连接池为阿里开源的Druid，项目的交互编码采用UTF-8，持久化框架采用的是MyBatis-Plus。</p> <p><strong>这里注意一点的是，我们在application.yml文件中的mybatis-plus节点下定义了Mapper的xml文件的存放位置，如下所示</strong></p> <div class="language-yaml line-numbers-mode"><pre class="language-yaml"><code><span class="token key atrule">spring</span><span class="token punctuation">:</span>
  <span class="token key atrule">mybatis-plus</span><span class="token punctuation">:</span>
    <span class="token key atrule">mapper-locations</span><span class="token punctuation">:</span> classpath<span class="token punctuation">:</span>/mapper/<span class="token important">*.xml</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div><p><strong>Mapper的xml文件位置在当前项目的classpath目录下的mapper目录下。也就是说，我们在使用MyBatis-Plus框架时，如果涉及到自己写SQL语句时，会将SQL语句写到XML文件中，而不是通过注解的方式写到接口的方法上。</strong></p> <h3 id="开发持久层"><a href="#开发持久层" class="header-anchor">#</a> 开发持久层</h3> <p>用户持久层主要是提供对于用户数据表的基本增删改查操作。持久化框架采用的是MyBatis-Plus，在项目的io.binghe.shop.user.mapper包下创建UserMapper接口，主要用作使用MyBatis-Plus框架操作用户数据表的基础Mapper接口，源码如下所示。</p> <div class="language-java line-numbers-mode"><pre class="language-java"><code><span class="token comment">/**
 * @author binghe
 * @version 1.0.0
 * @description 用户Mapper
 */</span>
<span class="token keyword">public</span> <span class="token keyword">interface</span> <span class="token class-name">UserMapper</span> <span class="token keyword">extends</span> <span class="token class-name">BaseMapper</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">User</span><span class="token punctuation">&gt;</span></span> <span class="token punctuation">{</span>
    
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br></div></div><p>可以看到，在UserMapper接口中没有定义任何方法，这是由于MyBatis-Plus框架中已经封装好了针对实体类的基础增删改查操作，而我们目前快速搭建三大微服务的过程中，使用MyBatis-Plus框架封装的基础增删改查操作就能够满足需求了。所以，在UserMapper接口中，未定义任何方法。</p> <p>接下来，在resources目录下创建mapper目录里创建UserMapper.xml文件，文件的内容如下所示。</p> <div class="language-xml line-numbers-mode"><pre class="language-xml"><code><span class="token prolog">&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;</span>
<span class="token doctype"><span class="token punctuation">&lt;!</span><span class="token doctype-tag">DOCTYPE</span> <span class="token name">mapper</span> <span class="token name">PUBLIC</span> <span class="token string">&quot;-//mybatis.org//DTD Mapper 3.0//EN&quot;</span> <span class="token string">&quot;http://mybatis.org/dtd/mybatis-3-mapper.dtd&quot;</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>mapper</span> <span class="token attr-name">namespace</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">&quot;</span>io.binghe.shop.user.mapper.UserMapper<span class="token punctuation">&quot;</span></span><span class="token punctuation">&gt;</span></span>
	
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>mapper</span><span class="token punctuation">&gt;</span></span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br></div></div><p>UserMapper.xml文件与UserMapper接口是一一对应的，UserMapper中定义的接口方法，都会在UserMapper.xml文件中写对应的SQL语句。由于UserMapper接口中位定义任何方法，所以在UserMapper.xml文件中，也就未声明任何SQL语句了。</p> <h3 id="开发业务逻辑层"><a href="#开发业务逻辑层" class="header-anchor">#</a> 开发业务逻辑层</h3> <p>用户微服务的业务逻辑层主要提供针对用户信息的业务逻辑开发，在io.binghe.shop.user.service包下创建UserService接口，源码如下所示。</p> <div class="language-java line-numbers-mode"><pre class="language-java"><code><span class="token comment">/**
 * @author binghe
 * @version 1.0.0
 * @description 用户业务接口
 */</span>
<span class="token keyword">public</span> <span class="token keyword">interface</span> <span class="token class-name">UserService</span> <span class="token punctuation">{</span>

    <span class="token comment">/**
     * 根据id获取用户信息
     */</span>
    <span class="token class-name">User</span> <span class="token function">getUserById</span><span class="token punctuation">(</span><span class="token class-name">Long</span> userId<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br></div></div><p>可以看到，在UserService接口中，定义了一个通过用户id获取用户信息的方法getUserById()，提供这个方法传入用户的id编号就可以获取到用户的信息。</p> <p>接下来，在io.binghe.shop.user.service.impl包下创建UserServiceImpl类，实现UserService接口，并实现UserService接口定义的方法getUserById()，UserServiceImpl类的源码如下所示。</p> <div class="language-java line-numbers-mode"><pre class="language-java"><code><span class="token comment">/**
 * @author binghe
 * @version 1.0.0
 * @description 用户业务实现类
 */</span>
<span class="token annotation punctuation">@Service</span>
<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">UserServiceImpl</span> <span class="token keyword">implements</span> <span class="token class-name">UserService</span> <span class="token punctuation">{</span>
    <span class="token annotation punctuation">@Autowired</span>
    <span class="token keyword">private</span> <span class="token class-name">UserMapper</span> userMapper<span class="token punctuation">;</span>

    <span class="token annotation punctuation">@Override</span>
    <span class="token keyword">public</span> <span class="token class-name">User</span> <span class="token function">getUserById</span><span class="token punctuation">(</span><span class="token class-name">Long</span> userId<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">return</span> userMapper<span class="token punctuation">.</span><span class="token function">selectById</span><span class="token punctuation">(</span>userId<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br></div></div><p>由于项目中使用了SpringBoot，SpringBoot又是基于Spring开发的，所以我们在项目开发过程中，都是使用Spring来管理Java对象的生命周期，也就是bean的生命周期。所以在UserServiceImpl类上标注了@Service注解，使用@Autowired注解注入了UserMapper对象，并在getUserById()中调用UserMapper对象的selectById()方法获取用户的基本信息。</p> <h3 id="开发接口层"><a href="#开发接口层" class="header-anchor">#</a> 开发接口层</h3> <p>用户微服务的接口层主要对外提供用户微服务的接口，在io.binghe.shop.user.controller包下创建UserController类，源码如下所示。</p> <div class="language-java line-numbers-mode"><pre class="language-java"><code><span class="token comment">/**
 * @author binghe
 * @version 1.0.0
 * @description 用户接口
 */</span>
<span class="token annotation punctuation">@Slf4j</span>
<span class="token annotation punctuation">@RestController</span>
<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">UserController</span> <span class="token punctuation">{</span>

    <span class="token annotation punctuation">@Autowired</span>
    <span class="token keyword">private</span> <span class="token class-name">UserService</span> userService<span class="token punctuation">;</span>

    <span class="token annotation punctuation">@GetMapping</span><span class="token punctuation">(</span>value <span class="token operator">=</span> <span class="token string">&quot;/get/{uid}&quot;</span><span class="token punctuation">)</span>
    <span class="token keyword">public</span> <span class="token class-name">User</span> <span class="token function">getUser</span><span class="token punctuation">(</span><span class="token annotation punctuation">@PathVariable</span><span class="token punctuation">(</span><span class="token string">&quot;uid&quot;</span><span class="token punctuation">)</span> <span class="token class-name">Long</span> uid<span class="token punctuation">)</span><span class="token punctuation">{</span>
        <span class="token class-name">User</span> user <span class="token operator">=</span> userService<span class="token punctuation">.</span><span class="token function">getUserById</span><span class="token punctuation">(</span>uid<span class="token punctuation">)</span><span class="token punctuation">;</span>
        log<span class="token punctuation">.</span><span class="token function">info</span><span class="token punctuation">(</span><span class="token string">&quot;获取到的用户信息为：{}&quot;</span><span class="token punctuation">,</span> <span class="token class-name">JSONObject</span><span class="token punctuation">.</span><span class="token function">toJSONString</span><span class="token punctuation">(</span>user<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token keyword">return</span> user<span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br></div></div><p>在UserController上标注了@RestController注解，表明UserController能够提供Restful风格的接口，同时在UserController类中使用@Autowired注解注入了UserService对象，在getUser()方法中调用UserService对象的getUserById()方法获取用户的信息，并返回用户的信息，同时在getUserById()方法上标注了@GetMapping注解表示这个接口采用HTTP GET方式访问，并定义了这个接口的访问路径。</p> <p>用户调用订单微服务的提交订单接口下单时，订单微服务会调用用户微服务的接口获取用户的基本信息。</p> <h3 id="开发服务启动类"><a href="#开发服务启动类" class="header-anchor">#</a> 开发服务启动类</h3> <p>在用户微服务的io.binghe.shop包下创建UserStarter类，作为用户微服务的启动类，源码如下所示。</p> <div class="language-java line-numbers-mode"><pre class="language-java"><code><span class="token comment">/**
 * @author binghe
 * @version 1.0.0
 * @description 启动用户服的类
 */</span>
<span class="token annotation punctuation">@SpringBootApplication</span>
<span class="token annotation punctuation">@EnableTransactionManagement</span><span class="token punctuation">(</span>proxyTargetClass <span class="token operator">=</span> <span class="token boolean">true</span><span class="token punctuation">)</span>
<span class="token annotation punctuation">@MapperScan</span><span class="token punctuation">(</span>value <span class="token operator">=</span> <span class="token punctuation">{</span> <span class="token string">&quot;io.binghe.shop.user.mapper&quot;</span> <span class="token punctuation">}</span><span class="token punctuation">)</span>
<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">UserStarter</span> <span class="token punctuation">{</span>

    <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token class-name">String</span><span class="token punctuation">[</span><span class="token punctuation">]</span> args<span class="token punctuation">)</span><span class="token punctuation">{</span>
        <span class="token class-name">SpringApplication</span><span class="token punctuation">.</span><span class="token function">run</span><span class="token punctuation">(</span><span class="token class-name">UserStarter</span><span class="token punctuation">.</span><span class="token keyword">class</span><span class="token punctuation">,</span> args<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br></div></div><p>至此，用户微服务开发完成。</p> <h2 id="商品微服务"><a href="#商品微服务" class="header-anchor">#</a> 商品微服务</h2> <p>商品微服务主要用来提供对于商品基础信息的增删改查操作，用户执行下单操作时，会从商品微服务中查询商品的基本信息，并完成商品的库存扣减操作。商品微服务的总体结构如下图所示。</p> <p><img alt="sa-2022-04-21-003" data-src="https://binghe001.github.io/assets/images/microservices/springcloudalibaba/sa-2022-04-21-003.png" loading="lazy" class="lazy"></p> <h3 id="项目搭建"><a href="#项目搭建" class="header-anchor">#</a> 项目搭建</h3> <p>商品微服务的搭建过程和用户微服务的搭建过程类似，只是在application.yml文件中的部分配置不同，在商品微服务的application.yml文件中，需要将端口修改为8070，基础访问路径修改为/product，应用名称修改为server-product，<strong>具体的源码可以到【冰河技术】星球获取，文末有优惠券。</strong></p> <h3 id="开发持久层-2"><a href="#开发持久层-2" class="header-anchor">#</a> 开发持久层</h3> <p>商品持久层主要提供对于商品数据表的增删改查操作，在io.binghe.shop.product.mapper包下创建ProductMapper接口，用于MyBatis-Plus操作商品数据表的基础Mapper接口，源码如下所示。</p> <div class="language-java line-numbers-mode"><pre class="language-java"><code><span class="token comment">/**
 * @author binghe
 * @version 1.0.0
 * @description 商品服务Mapper接口
 */</span>
<span class="token keyword">public</span> <span class="token keyword">interface</span> <span class="token class-name">ProductMapper</span> <span class="token keyword">extends</span> <span class="token class-name">BaseMapper</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">Product</span><span class="token punctuation">&gt;</span></span> <span class="token punctuation">{</span>

    <span class="token comment">/**
     * 扣减商品库存
     */</span>
    <span class="token keyword">int</span> <span class="token function">updateProductStockById</span><span class="token punctuation">(</span><span class="token annotation punctuation">@Param</span><span class="token punctuation">(</span><span class="token string">&quot;count&quot;</span><span class="token punctuation">)</span> <span class="token class-name">Integer</span> count<span class="token punctuation">,</span> <span class="token annotation punctuation">@Param</span><span class="token punctuation">(</span><span class="token string">&quot;id&quot;</span><span class="token punctuation">)</span> <span class="token class-name">Long</span> id<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br></div></div><p>可以看到，在ProductMapper接口中除了可以使用MyBatis-Plus框架提供的基础增删改查外，还提供了一个单独的扣减商品库存的方法updateProductStockById()，传入需要扣减的商品数量和商品的id就可以实现商品库存的扣减操作。</p> <p>接下来，在resources的mapper目录下创建ProductMapper.xml文件，在ProductMapper.xml文件中实现updateProductStockById对应的SQL语句，如下所示。</p> <div class="language-xml line-numbers-mode"><pre class="language-xml"><code><span class="token prolog">&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;</span>
<span class="token doctype"><span class="token punctuation">&lt;!</span><span class="token doctype-tag">DOCTYPE</span> <span class="token name">mapper</span> <span class="token name">PUBLIC</span> <span class="token string">&quot;-//mybatis.org//DTD Mapper 3.0//EN&quot;</span> <span class="token string">&quot;http://mybatis.org/dtd/mybatis-3-mapper.dtd&quot;</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>mapper</span> <span class="token attr-name">namespace</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">&quot;</span>io.binghe.shop.product.mapper.ProductMapper<span class="token punctuation">&quot;</span></span><span class="token punctuation">&gt;</span></span>
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>update</span> <span class="token attr-name">id</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">&quot;</span>updateProductStockById<span class="token punctuation">&quot;</span></span><span class="token punctuation">&gt;</span></span>
        update t_product set t_pro_stock = t_pro_stock - #{count} where id = #{id}
    <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>update</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>mapper</span><span class="token punctuation">&gt;</span></span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br></div></div><h3 id="开发业务逻辑层-2"><a href="#开发业务逻辑层-2" class="header-anchor">#</a> 开发业务逻辑层</h3> <p>商品微服务的业务逻辑层主要提供针对商品信息的业务逻辑操作，在io.binghe.shop.product.service包下创建ProductService接口，源码如下所示。</p> <div class="language-java line-numbers-mode"><pre class="language-java"><code><span class="token comment">/**
 * @author binghe
 * @version 1.0.0
 * @description 商品Service接口
 */</span>
<span class="token keyword">public</span> <span class="token keyword">interface</span> <span class="token class-name">ProductService</span> <span class="token punctuation">{</span>

    <span class="token comment">/**
     * 根据商品id获取商品信息
     */</span>
    <span class="token class-name">Product</span> <span class="token function">getProductById</span><span class="token punctuation">(</span><span class="token class-name">Long</span> pid<span class="token punctuation">)</span><span class="token punctuation">;</span>


    <span class="token comment">/**
     * 扣减商品库存
     */</span>
    <span class="token keyword">int</span> <span class="token function">updateProductStockById</span><span class="token punctuation">(</span><span class="token class-name">Integer</span> count<span class="token punctuation">,</span> <span class="token class-name">Long</span> id<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br></div></div><p>可以看到，在ProductService接口中定义了获取商品信息的方法getProductById()和扣减商品库存的方法updateProductStockById()。</p> <p>接下来，在io.binghe.shop.product.service.impl包下创建ProductServiceImpl类，实现ProductService接口，并实现ProductService接口中定义的getProductById()方法和updateProductStockById()方法，如下所示。</p> <div class="language-java line-numbers-mode"><pre class="language-java"><code><span class="token comment">/**
 * @author binghe
 * @version 1.0.0
 * @description 商品业务实现类
 */</span>
<span class="token annotation punctuation">@Service</span>
<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">ProductServiceImpl</span> <span class="token keyword">implements</span> <span class="token class-name">ProductService</span> <span class="token punctuation">{</span>
    <span class="token annotation punctuation">@Autowired</span>
    <span class="token keyword">private</span> <span class="token class-name">ProductMapper</span> productMapper<span class="token punctuation">;</span>
    <span class="token annotation punctuation">@Override</span>
    <span class="token keyword">public</span> <span class="token class-name">Product</span> <span class="token function">getProductById</span><span class="token punctuation">(</span><span class="token class-name">Long</span> pid<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">return</span> productMapper<span class="token punctuation">.</span><span class="token function">selectById</span><span class="token punctuation">(</span>pid<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token annotation punctuation">@Override</span>
    <span class="token keyword">public</span> <span class="token keyword">int</span> <span class="token function">updateProductStockById</span><span class="token punctuation">(</span><span class="token class-name">Integer</span> count<span class="token punctuation">,</span> <span class="token class-name">Long</span> id<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">return</span> productMapper<span class="token punctuation">.</span><span class="token function">updateProductStockById</span><span class="token punctuation">(</span>count<span class="token punctuation">,</span> id<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br></div></div><p>在ProductServiceImpl类中，getProductById()方法使用的是MyBatis-Plus框架中提供的selectById()方法获取商品的信息，updateProductStockById()方法中使用的是ProductMapper接口中定义的updateProductStockById()方法扣减商品的库存。</p> <h3 id="开发接口层-2"><a href="#开发接口层-2" class="header-anchor">#</a> 开发接口层</h3> <p>商品微服务的接口层主要是商品对外提供的接口，在io.binghe.shop.product.controller包下创建ProductController类，并在类上标注@RestController注解表示ProductController类提供的是Restful风格的接口。ProductController类的源码如下所示。</p> <div class="language-java line-numbers-mode"><pre class="language-java"><code><span class="token comment">/**
 * @author binghe
 * @version 1.0.0
 * @description 商品api
 */</span>
<span class="token annotation punctuation">@RestController</span>
<span class="token annotation punctuation">@Slf4j</span>
<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">ProductController</span> <span class="token punctuation">{</span>

    <span class="token annotation punctuation">@Autowired</span>
    <span class="token keyword">private</span> <span class="token class-name">ProductService</span> productService<span class="token punctuation">;</span>

    <span class="token annotation punctuation">@GetMapping</span><span class="token punctuation">(</span>value <span class="token operator">=</span> <span class="token string">&quot;/get/{pid}&quot;</span><span class="token punctuation">)</span>
    <span class="token keyword">public</span> <span class="token class-name">Product</span> <span class="token function">getProduct</span><span class="token punctuation">(</span><span class="token annotation punctuation">@PathVariable</span><span class="token punctuation">(</span><span class="token string">&quot;pid&quot;</span><span class="token punctuation">)</span> <span class="token class-name">Long</span> pid<span class="token punctuation">)</span><span class="token punctuation">{</span>
        <span class="token class-name">Product</span> product <span class="token operator">=</span> productService<span class="token punctuation">.</span><span class="token function">getProductById</span><span class="token punctuation">(</span>pid<span class="token punctuation">)</span><span class="token punctuation">;</span>
        log<span class="token punctuation">.</span><span class="token function">info</span><span class="token punctuation">(</span><span class="token string">&quot;获取到的商品信息为：{}&quot;</span><span class="token punctuation">,</span> <span class="token class-name">JSONObject</span><span class="token punctuation">.</span><span class="token function">toJSONString</span><span class="token punctuation">(</span>product<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token keyword">return</span> product<span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token annotation punctuation">@GetMapping</span><span class="token punctuation">(</span>value <span class="token operator">=</span> <span class="token string">&quot;/update_count/{pid}/{count}&quot;</span><span class="token punctuation">)</span>
    <span class="token keyword">public</span> <span class="token class-name">Result</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">Integer</span><span class="token punctuation">&gt;</span></span> <span class="token function">updateCount</span><span class="token punctuation">(</span><span class="token annotation punctuation">@PathVariable</span><span class="token punctuation">(</span><span class="token string">&quot;pid&quot;</span><span class="token punctuation">)</span> <span class="token class-name">Long</span> pid<span class="token punctuation">,</span> <span class="token annotation punctuation">@PathVariable</span><span class="token punctuation">(</span><span class="token string">&quot;count&quot;</span><span class="token punctuation">)</span> <span class="token class-name">Integer</span> count<span class="token punctuation">)</span><span class="token punctuation">{</span>
        log<span class="token punctuation">.</span><span class="token function">info</span><span class="token punctuation">(</span><span class="token string">&quot;更新商品库存传递的参数为: 商品id:{}, 购买数量:{} &quot;</span><span class="token punctuation">,</span> pid<span class="token punctuation">,</span> count<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token keyword">int</span> updateCount <span class="token operator">=</span> productService<span class="token punctuation">.</span><span class="token function">updateProductStockById</span><span class="token punctuation">(</span>count<span class="token punctuation">,</span> pid<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token class-name">Result</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">Integer</span><span class="token punctuation">&gt;</span></span> result <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">Result</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token punctuation">&gt;</span></span><span class="token punctuation">(</span><span class="token class-name">HttpCode</span><span class="token punctuation">.</span>SUCCESS<span class="token punctuation">,</span> <span class="token string">&quot;执行成功&quot;</span><span class="token punctuation">,</span> updateCount<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token keyword">return</span> result<span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br><span class="line-number">26</span><br><span class="line-number">27</span><br></div></div><p>可以看到，在ProductController类中，提供了一个获取商品信息的接口和扣减商品库存的接口，用户调用订单微服务的提交订单接口下单时，订单微服务会调用商品微服务的接口获取商品的基本信息并扣减商品的库存。</p> <h3 id="开发服务启动类-2"><a href="#开发服务启动类-2" class="header-anchor">#</a> 开发服务启动类</h3> <p>在商品微服务的io.binghe.shop包下创建ProductStarter类，作为商品微服务的启动类，源码如下所示。</p> <div class="language-java line-numbers-mode"><pre class="language-java"><code><span class="token comment">/**
 * @author binghe
 * @version 1.0.0
 * @description 商品服务启动类
 */</span>
<span class="token annotation punctuation">@SpringBootApplication</span>
<span class="token annotation punctuation">@MapperScan</span><span class="token punctuation">(</span>value <span class="token operator">=</span> <span class="token punctuation">{</span> <span class="token string">&quot;io.binghe.shop.product.mapper&quot;</span> <span class="token punctuation">}</span><span class="token punctuation">)</span>
<span class="token annotation punctuation">@EnableTransactionManagement</span><span class="token punctuation">(</span>proxyTargetClass <span class="token operator">=</span> <span class="token boolean">true</span><span class="token punctuation">)</span>
<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">ProductStarter</span> <span class="token punctuation">{</span>

    <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token class-name">String</span><span class="token punctuation">[</span><span class="token punctuation">]</span> args<span class="token punctuation">)</span><span class="token punctuation">{</span>
        <span class="token class-name">SpringApplication</span><span class="token punctuation">.</span><span class="token function">run</span><span class="token punctuation">(</span><span class="token class-name">ProductStarter</span><span class="token punctuation">.</span><span class="token keyword">class</span><span class="token punctuation">,</span> args<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br></div></div><p>至此，商品微服务开发完毕。</p> <h2 id="订单微服务"><a href="#订单微服务" class="header-anchor">#</a> 订单微服务</h2> <p>订单微服务主要用来提供用户下单操作的业务逻辑，用户执行下单操作时，订单微服务会调用用户微服务的接口获取用户的基本信息，会调用商品微服务的接口获取商品的基本信息。在订单微服务中校验用户的合法性和校验商品库存是否充足，如果用户合法并且商品库存充足，就会向订单数据表中记录订单信息并调用商品微服务的接口来扣减商品的库存。</p> <p>订单微服务的总体结构如下图所示。</p> <p><img alt="sa-2022-04-21-004" data-src="https://binghe001.github.io/assets/images/microservices/springcloudalibaba/sa-2022-04-21-004.png" loading="lazy" class="lazy"></p> <h3 id="项目搭建-2"><a href="#项目搭建-2" class="header-anchor">#</a> 项目搭建</h3> <p>订单微服务的项目搭建过程与用户微服务和商品微服务的项目搭建过程类似，只是在application.yml文件中的部分配置不同，在订单微服务的application.yml文件中，需要将端口修改为8080，基础访问路径修改为/order，应用名称修改为server-order，<strong>具体的源码可以到【冰河技术】星球获取，文末有优惠券。</strong></p> <h3 id="开发持久层-3"><a href="#开发持久层-3" class="header-anchor">#</a> 开发持久层</h3> <p>订单微服务的持久层主要提供对订单数据表的增删改查操作，订单服务会涉及到对t_order订单数据表和t_order_item订单条目数据表的操作，所以，在io.binghe.shop.order.mapper包下会创建OrderMapper和OrderItemMapper两个接口，如下所示。</p> <ul><li>OrderMapper接口</li></ul> <div class="language-java line-numbers-mode"><pre class="language-java"><code><span class="token comment">/**
 * @author binghe
 * @version 1.0.0
 * @description 订单Mapper
 */</span>
<span class="token keyword">public</span> <span class="token keyword">interface</span> <span class="token class-name">OrderMapper</span> <span class="token keyword">extends</span> <span class="token class-name">BaseMapper</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">Order</span><span class="token punctuation">&gt;</span></span> <span class="token punctuation">{</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br></div></div><ul><li>OrderItem接口</li></ul> <div class="language-java line-numbers-mode"><pre class="language-java"><code><span class="token comment">/**
 * @author binghe
 * @version 1.0.0
 * @description 订单条目Mapper
 */</span>
<span class="token keyword">public</span> <span class="token keyword">interface</span> <span class="token class-name">OrderItemMapper</span> <span class="token keyword">extends</span> <span class="token class-name">BaseMapper</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">OrderItem</span><span class="token punctuation">&gt;</span></span> <span class="token punctuation">{</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br></div></div><p>由于在订单微服务中，对于订单数据表和订单条目数据表的操作，使用MyBatis-Plus框架提供的基本增删改查功能就能满足需求，所以在OrderMapper和OrderItemMapper接口中并没有定义任何方法。</p> <h3 id="开发业务逻辑层-3"><a href="#开发业务逻辑层-3" class="header-anchor">#</a> 开发业务逻辑层</h3> <p>订单微服务的业务逻辑层主要完成提交订单的业务逻辑，用户执行下单操作时，订单微服务会调用用户微服务的接口获取用户的基本信息，会调用商品微服务的接口获取商品的基本信息。在订单微服务中校验用户的合法性和校验商品库存是否充足，如果用户合法并且商品库存充足，就会向订单数据表中记录订单信息并调用商品微服务的接口来扣减商品的库存。</p> <p>在io.binghe.shop.order.service包下创建OrderService接口，在接口中定义一个保存订单的接口saveOrder()，源码如下所示。</p> <div class="language-java line-numbers-mode"><pre class="language-java"><code><span class="token comment">/**
 * @author binghe
 * @version 1.0.0
 * @description 订单业务接口
 */</span>
<span class="token keyword">public</span> <span class="token keyword">interface</span> <span class="token class-name">OrderService</span> <span class="token punctuation">{</span>
    <span class="token comment">/**
     * 保存订单
     */</span>
    <span class="token keyword">void</span> <span class="token function">saveOrder</span><span class="token punctuation">(</span><span class="token class-name">OrderParams</span> orderParams<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br></div></div><p>接下来，在io.binghe.shop.order.service.impl包下创建OrderServiceImpl类，实现OrderService接口，源码如下所示。</p> <div class="language-java line-numbers-mode"><pre class="language-java"><code><span class="token comment">/**
 * @author binghe
 * @version 1.0.0
 * @description
 */</span>
<span class="token annotation punctuation">@Service</span>
<span class="token annotation punctuation">@Slf4j</span>
<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">OrderServiceImpl</span> <span class="token keyword">implements</span> <span class="token class-name">OrderService</span> <span class="token punctuation">{</span>

    <span class="token annotation punctuation">@Autowired</span>
    <span class="token keyword">private</span> <span class="token class-name">OrderMapper</span> orderMapper<span class="token punctuation">;</span>
    <span class="token annotation punctuation">@Autowired</span>
    <span class="token keyword">private</span> <span class="token class-name">OrderItemMapper</span> orderItemMapper<span class="token punctuation">;</span>
    <span class="token annotation punctuation">@Autowired</span>
    <span class="token keyword">private</span> <span class="token class-name">RestTemplate</span> restTemplate<span class="token punctuation">;</span>


    <span class="token annotation punctuation">@Override</span>
    <span class="token annotation punctuation">@Transactional</span><span class="token punctuation">(</span>rollbackFor <span class="token operator">=</span> <span class="token class-name">Exception</span><span class="token punctuation">.</span><span class="token keyword">class</span><span class="token punctuation">)</span>
    <span class="token keyword">public</span> <span class="token keyword">void</span> <span class="token function">saveOrder</span><span class="token punctuation">(</span><span class="token class-name">OrderParams</span> orderParams<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">if</span> <span class="token punctuation">(</span>orderParams<span class="token punctuation">.</span><span class="token function">isEmpty</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
            <span class="token keyword">throw</span> <span class="token keyword">new</span> <span class="token class-name">RuntimeException</span><span class="token punctuation">(</span><span class="token string">&quot;参数异常: &quot;</span> <span class="token operator">+</span> <span class="token class-name">JSONObject</span><span class="token punctuation">.</span><span class="token function">toJSONString</span><span class="token punctuation">(</span>orderParams<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>

        <span class="token class-name">User</span> user <span class="token operator">=</span> restTemplate<span class="token punctuation">.</span><span class="token function">getForObject</span><span class="token punctuation">(</span><span class="token string">&quot;http://localhost:8060/user/get/&quot;</span> <span class="token operator">+</span> orderParams<span class="token punctuation">.</span><span class="token function">getUserId</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token class-name">User</span><span class="token punctuation">.</span><span class="token keyword">class</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token keyword">if</span> <span class="token punctuation">(</span>user <span class="token operator">==</span> <span class="token keyword">null</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
            <span class="token keyword">throw</span> <span class="token keyword">new</span> <span class="token class-name">RuntimeException</span><span class="token punctuation">(</span><span class="token string">&quot;未获取到用户信息: &quot;</span> <span class="token operator">+</span> <span class="token class-name">JSONObject</span><span class="token punctuation">.</span><span class="token function">toJSONString</span><span class="token punctuation">(</span>orderParams<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
        <span class="token class-name">Product</span> product <span class="token operator">=</span> restTemplate<span class="token punctuation">.</span><span class="token function">getForObject</span><span class="token punctuation">(</span><span class="token string">&quot;http://localhost:8070/product/get/&quot;</span> <span class="token operator">+</span> orderParams<span class="token punctuation">.</span><span class="token function">getProductId</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token class-name">Product</span><span class="token punctuation">.</span><span class="token keyword">class</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token keyword">if</span> <span class="token punctuation">(</span>product <span class="token operator">==</span> <span class="token keyword">null</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
            <span class="token keyword">throw</span> <span class="token keyword">new</span> <span class="token class-name">RuntimeException</span><span class="token punctuation">(</span><span class="token string">&quot;未获取到商品信息: &quot;</span> <span class="token operator">+</span> <span class="token class-name">JSONObject</span><span class="token punctuation">.</span><span class="token function">toJSONString</span><span class="token punctuation">(</span>orderParams<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
        <span class="token keyword">if</span> <span class="token punctuation">(</span>product<span class="token punctuation">.</span><span class="token function">getProStock</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">&lt;</span> orderParams<span class="token punctuation">.</span><span class="token function">getCount</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
            <span class="token keyword">throw</span> <span class="token keyword">new</span> <span class="token class-name">RuntimeException</span><span class="token punctuation">(</span><span class="token string">&quot;商品库存不足: &quot;</span> <span class="token operator">+</span> <span class="token class-name">JSONObject</span><span class="token punctuation">.</span><span class="token function">toJSONString</span><span class="token punctuation">(</span>orderParams<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
        <span class="token class-name">Order</span> order <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">Order</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        order<span class="token punctuation">.</span><span class="token function">setAddress</span><span class="token punctuation">(</span>user<span class="token punctuation">.</span><span class="token function">getAddress</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        order<span class="token punctuation">.</span><span class="token function">setPhone</span><span class="token punctuation">(</span>user<span class="token punctuation">.</span><span class="token function">getPhone</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        order<span class="token punctuation">.</span><span class="token function">setUserId</span><span class="token punctuation">(</span>user<span class="token punctuation">.</span><span class="token function">getId</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        order<span class="token punctuation">.</span><span class="token function">setUsername</span><span class="token punctuation">(</span>user<span class="token punctuation">.</span><span class="token function">getUsername</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        order<span class="token punctuation">.</span><span class="token function">setTotalPrice</span><span class="token punctuation">(</span>product<span class="token punctuation">.</span><span class="token function">getProPrice</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">multiply</span><span class="token punctuation">(</span><span class="token class-name">BigDecimal</span><span class="token punctuation">.</span><span class="token function">valueOf</span><span class="token punctuation">(</span>orderParams<span class="token punctuation">.</span><span class="token function">getCount</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        orderMapper<span class="token punctuation">.</span><span class="token function">insert</span><span class="token punctuation">(</span>order<span class="token punctuation">)</span><span class="token punctuation">;</span>

        <span class="token class-name">OrderItem</span> orderItem <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">OrderItem</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        orderItem<span class="token punctuation">.</span><span class="token function">setNumber</span><span class="token punctuation">(</span>orderParams<span class="token punctuation">.</span><span class="token function">getCount</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        orderItem<span class="token punctuation">.</span><span class="token function">setOrderId</span><span class="token punctuation">(</span>order<span class="token punctuation">.</span><span class="token function">getId</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        orderItem<span class="token punctuation">.</span><span class="token function">setProId</span><span class="token punctuation">(</span>product<span class="token punctuation">.</span><span class="token function">getId</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        orderItem<span class="token punctuation">.</span><span class="token function">setProName</span><span class="token punctuation">(</span>product<span class="token punctuation">.</span><span class="token function">getProName</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        orderItem<span class="token punctuation">.</span><span class="token function">setProPrice</span><span class="token punctuation">(</span>product<span class="token punctuation">.</span><span class="token function">getProPrice</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        orderItemMapper<span class="token punctuation">.</span><span class="token function">insert</span><span class="token punctuation">(</span>orderItem<span class="token punctuation">)</span><span class="token punctuation">;</span>

        <span class="token class-name">Result</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token class-name">Integer</span><span class="token punctuation">&gt;</span></span> result <span class="token operator">=</span> restTemplate<span class="token punctuation">.</span><span class="token function">getForObject</span><span class="token punctuation">(</span><span class="token string">&quot;http://localhost:8070/product/update_count/&quot;</span> <span class="token operator">+</span> orderParams<span class="token punctuation">.</span><span class="token function">getProductId</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">+</span> <span class="token string">&quot;/&quot;</span> <span class="token operator">+</span> orderParams<span class="token punctuation">.</span><span class="token function">getCount</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token class-name">Result</span><span class="token punctuation">.</span><span class="token keyword">class</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token keyword">if</span> <span class="token punctuation">(</span>result<span class="token punctuation">.</span><span class="token function">getCode</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">!=</span> <span class="token class-name">HttpCode</span><span class="token punctuation">.</span>SUCCESS<span class="token punctuation">)</span><span class="token punctuation">{</span>
            <span class="token keyword">throw</span> <span class="token keyword">new</span> <span class="token class-name">RuntimeException</span><span class="token punctuation">(</span><span class="token string">&quot;库存扣减失败&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
        log<span class="token punctuation">.</span><span class="token function">info</span><span class="token punctuation">(</span><span class="token string">&quot;库存扣减成功&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br><span class="line-number">26</span><br><span class="line-number">27</span><br><span class="line-number">28</span><br><span class="line-number">29</span><br><span class="line-number">30</span><br><span class="line-number">31</span><br><span class="line-number">32</span><br><span class="line-number">33</span><br><span class="line-number">34</span><br><span class="line-number">35</span><br><span class="line-number">36</span><br><span class="line-number">37</span><br><span class="line-number">38</span><br><span class="line-number">39</span><br><span class="line-number">40</span><br><span class="line-number">41</span><br><span class="line-number">42</span><br><span class="line-number">43</span><br><span class="line-number">44</span><br><span class="line-number">45</span><br><span class="line-number">46</span><br><span class="line-number">47</span><br><span class="line-number">48</span><br><span class="line-number">49</span><br><span class="line-number">50</span><br><span class="line-number">51</span><br><span class="line-number">52</span><br><span class="line-number">53</span><br><span class="line-number">54</span><br><span class="line-number">55</span><br><span class="line-number">56</span><br><span class="line-number">57</span><br><span class="line-number">58</span><br></div></div><p>可以看到，在OrderServiceImpl类的实现中，使用了OrderMapper、OrderItemMapper和RestTemplate，RestTemplate主要用来实现远程调用。</p> <p>在saveOrder()方法的实现中，实现的主要逻辑如下。</p> <p>（1）判断orderParams封装的参数是否为空，如果参数为空，则抛出参数异常。</p> <p>（2）通过RestTemplate调用用户微服务获取用户的基本信息，如果获取的用户信息为空，则抛出未获取到用户信息的异常。</p> <p>（3）通过RestTemplate调用商品微服务获取商品的基本信息，如果获取的商品信息为空，则抛出未获取到商品信息的异常。</p> <p>（4）判断商品的库存是否小于待扣减的商品数量，如果商品的库存小于待扣减的商品数量，则抛出商品库存不足的异常。</p> <p>（5）如果orderParams封装的参数不为空，并且获取的用户信息和商品信息不为空，同时商品的库存充足，则创建订单对象保存订单信息，创建订单条目对象，保存订单条目信息。</p> <p>（6）调用商品微服务的接口扣减商品库存。</p> <h3 id="开发接口层-3"><a href="#开发接口层-3" class="header-anchor">#</a> 开发接口层</h3> <p>订单微服务的接口层主要是订单微服务对外提供相应的接口，在io.binghe.shop.order.controller包下创建OrderController类，并在OrderController类上添加@RestController注解，表示OrderController类提供的接口是Restful风格的接口，OrderController类的源码如下所示。</p> <div class="language-java line-numbers-mode"><pre class="language-java"><code><span class="token annotation punctuation">@Slf4j</span>
<span class="token annotation punctuation">@RestController</span>
<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">OrderController</span> <span class="token punctuation">{</span>
    <span class="token annotation punctuation">@Autowired</span>
    <span class="token keyword">private</span> <span class="token class-name">OrderService</span> orderService<span class="token punctuation">;</span>

    <span class="token annotation punctuation">@GetMapping</span><span class="token punctuation">(</span>value <span class="token operator">=</span> <span class="token string">&quot;/submit_order&quot;</span><span class="token punctuation">)</span>
    <span class="token keyword">public</span> <span class="token class-name">String</span> <span class="token function">submitOrder</span><span class="token punctuation">(</span><span class="token class-name">OrderParams</span> orderParams<span class="token punctuation">)</span><span class="token punctuation">{</span>
        log<span class="token punctuation">.</span><span class="token function">info</span><span class="token punctuation">(</span><span class="token string">&quot;提交订单时传递的参数:{}&quot;</span><span class="token punctuation">,</span> <span class="token class-name">JSONObject</span><span class="token punctuation">.</span><span class="token function">toJSONString</span><span class="token punctuation">(</span>orderParams<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        orderService<span class="token punctuation">.</span><span class="token function">saveOrder</span><span class="token punctuation">(</span>orderParams<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token keyword">return</span> <span class="token string">&quot;success&quot;</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br></div></div><p>可以看到，OrderController类提供的接口就比较简单了，通过传入相应的参数，调用OrderService的saveOrder方法完成下单操作。</p> <h3 id="开发服务启动类-3"><a href="#开发服务启动类-3" class="header-anchor">#</a> 开发服务启动类</h3> <p>在订单微服务的io.binghe.shop包下创建OrderStarter类，作为订单微服务的启动类，源码如下所示。</p> <div class="language-java line-numbers-mode"><pre class="language-java"><code><span class="token comment">/**
 * @author binghe
 * @version 1.0.0
 * @description 订单服务启动类
 */</span>
<span class="token annotation punctuation">@SpringBootApplication</span>
<span class="token annotation punctuation">@EnableTransactionManagement</span><span class="token punctuation">(</span>proxyTargetClass <span class="token operator">=</span> <span class="token boolean">true</span><span class="token punctuation">)</span>
<span class="token annotation punctuation">@MapperScan</span><span class="token punctuation">(</span>value <span class="token operator">=</span> <span class="token punctuation">{</span> <span class="token string">&quot;io.binghe.shop.order.mapper&quot;</span> <span class="token punctuation">}</span><span class="token punctuation">)</span>
<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">OrderStarter</span> <span class="token punctuation">{</span>
    <span class="token keyword">public</span> <span class="token keyword">static</span> <span class="token keyword">void</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token class-name">String</span><span class="token punctuation">[</span><span class="token punctuation">]</span> args<span class="token punctuation">)</span><span class="token punctuation">{</span>
        <span class="token class-name">SpringApplication</span><span class="token punctuation">.</span><span class="token function">run</span><span class="token punctuation">(</span><span class="token class-name">OrderStarter</span><span class="token punctuation">.</span><span class="token keyword">class</span><span class="token punctuation">,</span> args<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br></div></div><h3 id="开发辅助类"><a href="#开发辅助类" class="header-anchor">#</a> 开发辅助类</h3> <p>在订单微服务中，使用了RestTemplate来完成远程服务的调用，关于RestTemplate的配置，在io.binghe.shop.order.config包下新建LoadBalanceConfig类，并在LoadBalanceConfig类上标注@Configuration注解，表示LoadBalanceConfig类是一个配置类，在LoadBalanceConfig类中使用@Bean注解将RestTemplate对象交由Spring管理，LoadBalanceConfig类的源码如下所示。</p> <div class="language-java line-numbers-mode"><pre class="language-java"><code><span class="token comment">/**
 * @author binghe
 * @version 1.0.0
 * @description 配置类
 */</span>
<span class="token annotation punctuation">@Configuration</span>
<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">LoadBalanceConfig</span> <span class="token punctuation">{</span>

    <span class="token annotation punctuation">@Bean</span>
    <span class="token keyword">public</span> <span class="token class-name">RestTemplate</span> <span class="token function">restTemplate</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
        <span class="token keyword">return</span> <span class="token keyword">new</span> <span class="token class-name">RestTemplate</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br></div></div><p>至此，订单微服务开发完成，接下来，我们进行测试。</p> <h2 id="测试项目"><a href="#测试项目" class="header-anchor">#</a> 测试项目</h2> <p>开发完成后，我们对快速搭建并开发完成的三大微服务进行简单的测试，在测试之前我们需要先在数据表中添加一些测试数据。</p> <h3 id="添加测试数据"><a href="#添加测试数据" class="header-anchor">#</a> 添加测试数据</h3> <p>（1）在用户表中添加一条id为1001的记录，如下所示。</p> <div class="language-sql line-numbers-mode"><pre class="language-sql"><code><span class="token keyword">INSERT</span> <span class="token keyword">INTO</span> <span class="token identifier"><span class="token punctuation">`</span>shop<span class="token punctuation">`</span></span><span class="token punctuation">.</span><span class="token identifier"><span class="token punctuation">`</span>t_user<span class="token punctuation">`</span></span><span class="token punctuation">(</span><span class="token identifier"><span class="token punctuation">`</span>id<span class="token punctuation">`</span></span><span class="token punctuation">,</span> <span class="token identifier"><span class="token punctuation">`</span>t_username<span class="token punctuation">`</span></span><span class="token punctuation">,</span> <span class="token identifier"><span class="token punctuation">`</span>t_password<span class="token punctuation">`</span></span><span class="token punctuation">,</span> <span class="token identifier"><span class="token punctuation">`</span>t_phone<span class="token punctuation">`</span></span><span class="token punctuation">,</span> <span class="token identifier"><span class="token punctuation">`</span>t_address<span class="token punctuation">`</span></span><span class="token punctuation">)</span> <span class="token keyword">VALUES</span> <span class="token punctuation">(</span><span class="token number">1001</span><span class="token punctuation">,</span> <span class="token string">'binghe'</span><span class="token punctuation">,</span> <span class="token string">'c26be8aaf53b15054896983b43eb6a65'</span><span class="token punctuation">,</span> <span class="token string">'13212345678'</span><span class="token punctuation">,</span> <span class="token string">'北京'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>（2）在商品数据表中添加几条商品记录，如下所示。</p> <div class="language-sql line-numbers-mode"><pre class="language-sql"><code><span class="token keyword">INSERT</span> <span class="token keyword">INTO</span> <span class="token identifier"><span class="token punctuation">`</span>shop<span class="token punctuation">`</span></span><span class="token punctuation">.</span><span class="token identifier"><span class="token punctuation">`</span>t_product<span class="token punctuation">`</span></span><span class="token punctuation">(</span><span class="token identifier"><span class="token punctuation">`</span>id<span class="token punctuation">`</span></span><span class="token punctuation">,</span> <span class="token identifier"><span class="token punctuation">`</span>t_pro_name<span class="token punctuation">`</span></span><span class="token punctuation">,</span> <span class="token identifier"><span class="token punctuation">`</span>t_pro_price<span class="token punctuation">`</span></span><span class="token punctuation">,</span> <span class="token identifier"><span class="token punctuation">`</span>t_pro_stock<span class="token punctuation">`</span></span><span class="token punctuation">)</span> <span class="token keyword">VALUES</span> <span class="token punctuation">(</span><span class="token number">1001</span><span class="token punctuation">,</span> <span class="token string">'华为'</span><span class="token punctuation">,</span> <span class="token number">2399.00</span><span class="token punctuation">,</span> <span class="token number">100</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token keyword">INSERT</span> <span class="token keyword">INTO</span> <span class="token identifier"><span class="token punctuation">`</span>shop<span class="token punctuation">`</span></span><span class="token punctuation">.</span><span class="token identifier"><span class="token punctuation">`</span>t_product<span class="token punctuation">`</span></span><span class="token punctuation">(</span><span class="token identifier"><span class="token punctuation">`</span>id<span class="token punctuation">`</span></span><span class="token punctuation">,</span> <span class="token identifier"><span class="token punctuation">`</span>t_pro_name<span class="token punctuation">`</span></span><span class="token punctuation">,</span> <span class="token identifier"><span class="token punctuation">`</span>t_pro_price<span class="token punctuation">`</span></span><span class="token punctuation">,</span> <span class="token identifier"><span class="token punctuation">`</span>t_pro_stock<span class="token punctuation">`</span></span><span class="token punctuation">)</span> <span class="token keyword">VALUES</span> <span class="token punctuation">(</span><span class="token number">1002</span><span class="token punctuation">,</span> <span class="token string">'小米'</span><span class="token punctuation">,</span> <span class="token number">1999.00</span><span class="token punctuation">,</span> <span class="token number">100</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token keyword">INSERT</span> <span class="token keyword">INTO</span> <span class="token identifier"><span class="token punctuation">`</span>shop<span class="token punctuation">`</span></span><span class="token punctuation">.</span><span class="token identifier"><span class="token punctuation">`</span>t_product<span class="token punctuation">`</span></span><span class="token punctuation">(</span><span class="token identifier"><span class="token punctuation">`</span>id<span class="token punctuation">`</span></span><span class="token punctuation">,</span> <span class="token identifier"><span class="token punctuation">`</span>t_pro_name<span class="token punctuation">`</span></span><span class="token punctuation">,</span> <span class="token identifier"><span class="token punctuation">`</span>t_pro_price<span class="token punctuation">`</span></span><span class="token punctuation">,</span> <span class="token identifier"><span class="token punctuation">`</span>t_pro_stock<span class="token punctuation">`</span></span><span class="token punctuation">)</span> <span class="token keyword">VALUES</span> <span class="token punctuation">(</span><span class="token number">1003</span><span class="token punctuation">,</span> <span class="token string">'iphone'</span><span class="token punctuation">,</span> <span class="token number">4999.00</span><span class="token punctuation">,</span> <span class="token number">100</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div><h3 id="测试库存不足的情况"><a href="#测试库存不足的情况" class="header-anchor">#</a> 测试库存不足的情况</h3> <p>（1）分别启动用户微服务、商品微服务和订单微服务。</p> <p>（2）查询id为1001的商品信息，如下所示。</p> <div class="language-sql line-numbers-mode"><pre class="language-sql"><code>mysql<span class="token operator">&gt;</span> <span class="token keyword">select</span> <span class="token operator">*</span> <span class="token keyword">from</span> t_product <span class="token keyword">where</span> id <span class="token operator">=</span> <span class="token number">1001</span><span class="token punctuation">;</span>
<span class="token operator">+</span><span class="token comment">------+------------+-------------+-------------+</span>
<span class="token operator">|</span> id   <span class="token operator">|</span> t_pro_name <span class="token operator">|</span> t_pro_price <span class="token operator">|</span> t_pro_stock <span class="token operator">|</span>
<span class="token operator">+</span><span class="token comment">------+------------+-------------+-------------+</span>
<span class="token operator">|</span> <span class="token number">1001</span> <span class="token operator">|</span> 华为       <span class="token operator">|</span>     <span class="token number">2399.00</span> <span class="token operator">|</span>         <span class="token number">100</span> <span class="token operator">|</span>
<span class="token operator">+</span><span class="token comment">------+------------+-------------+-------------+</span>
<span class="token number">1</span> <span class="token keyword">row</span> <span class="token operator">in</span> <span class="token keyword">set</span> <span class="token punctuation">(</span><span class="token number">0.00</span> sec<span class="token punctuation">)</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br></div></div><p>可以看到，id为1001的商品的库存为100。</p> <p>（3）查询订单表和订单条目表中的数据，如下所示。</p> <ul><li>查询订单表</li></ul> <div class="language-sql line-numbers-mode"><pre class="language-sql"><code>mysql<span class="token operator">&gt;</span> <span class="token keyword">select</span> <span class="token operator">*</span> <span class="token keyword">from</span> t_order<span class="token punctuation">;</span>
Empty <span class="token keyword">set</span> <span class="token punctuation">(</span><span class="token number">0.00</span> sec<span class="token punctuation">)</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div><p>可以看到，订单数据表的数据为空。</p> <ul><li>查询订单条目表</li></ul> <div class="language-sql line-numbers-mode"><pre class="language-sql"><code>mysql<span class="token operator">&gt;</span> <span class="token keyword">select</span> <span class="token operator">*</span> <span class="token keyword">from</span> t_order_item<span class="token punctuation">;</span>
Empty <span class="token keyword">set</span> <span class="token punctuation">(</span><span class="token number">0.00</span> sec<span class="token punctuation">)</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div><p>可以看到，订单条目数据表的数据为空。</p> <p>（4）在浏览器中调用订单微服务的下单接口，传入的商品数量为1001，如下所示。</p> <p><img alt="sa-2022-04-21-005" data-src="https://binghe001.github.io/assets/images/microservices/springcloudalibaba/sa-2022-04-21-005.png" loading="lazy" class="lazy"></p> <p>可以看到，返回的信息中，code为500，codeMsg输出的信息为执行失败，data返回的结果为商品库存不足，并且输出了提交的参数信息。</p> <p>（5）再次查询id为1001的商品信息，如下所示。</p> <div class="language-sql line-numbers-mode"><pre class="language-sql"><code>mysql<span class="token operator">&gt;</span> <span class="token keyword">select</span> <span class="token operator">*</span> <span class="token keyword">from</span> t_product <span class="token keyword">where</span> id <span class="token operator">=</span> <span class="token number">1001</span><span class="token punctuation">;</span>
<span class="token operator">+</span><span class="token comment">------+------------+-------------+-------------+</span>
<span class="token operator">|</span> id   <span class="token operator">|</span> t_pro_name <span class="token operator">|</span> t_pro_price <span class="token operator">|</span> t_pro_stock <span class="token operator">|</span>
<span class="token operator">+</span><span class="token comment">------+------------+-------------+-------------+</span>
<span class="token operator">|</span> <span class="token number">1001</span> <span class="token operator">|</span> 华为       <span class="token operator">|</span>     <span class="token number">2399.00</span> <span class="token operator">|</span>         <span class="token number">100</span> <span class="token operator">|</span>
<span class="token operator">+</span><span class="token comment">------+------------+-------------+-------------+</span>
<span class="token number">1</span> <span class="token keyword">row</span> <span class="token operator">in</span> <span class="token keyword">set</span> <span class="token punctuation">(</span><span class="token number">0.00</span> sec<span class="token punctuation">)</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br></div></div><p>可以看到，商品id为1001的商品库存仍为100，并没有减少。</p> <p>（6）再次查询订单表和订单条目表中的数据，如下所示。</p> <ul><li>查询订单表</li></ul> <div class="language-sql line-numbers-mode"><pre class="language-sql"><code>mysql<span class="token operator">&gt;</span> <span class="token keyword">select</span> <span class="token operator">*</span> <span class="token keyword">from</span> t_order<span class="token punctuation">;</span>
Empty <span class="token keyword">set</span> <span class="token punctuation">(</span><span class="token number">0.00</span> sec<span class="token punctuation">)</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div><p>可以看到，订单数据表的数据为空。</p> <ul><li>查询订单条目表</li></ul> <div class="language-sql line-numbers-mode"><pre class="language-sql"><code>mysql<span class="token operator">&gt;</span> <span class="token keyword">select</span> <span class="token operator">*</span> <span class="token keyword">from</span> t_order_item<span class="token punctuation">;</span>
Empty <span class="token keyword">set</span> <span class="token punctuation">(</span><span class="token number">0.00</span> sec<span class="token punctuation">)</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div><p>可以看到，订单条目数据表的数据为空。</p> <p><strong>综上，当提交订单时传入的商品数量大于商品的库存数量时，系统会抛出异常，并不会执行提交订单和扣减库存的操作。</strong></p> <h3 id="测试正常下单的情况"><a href="#测试正常下单的情况" class="header-anchor">#</a> 测试正常下单的情况</h3> <p>（1）在测试库存不足的情况的基础上，我们将调用提交订单的接口时传入的商品数量修改为10，如下所示。</p> <p><img alt="sa-2022-04-21-006" data-src="https://binghe001.github.io/assets/images/microservices/springcloudalibaba/sa-2022-04-21-006.png" loading="lazy" class="lazy"></p> <p>可以看到，当商品库存充足时，调用订单微服务的下单接口，返回的数据为success表示下单成功。</p> <p>（2）再次查询id为1001的商品信息，如下所示。</p> <div class="language-java line-numbers-mode"><pre class="language-java"><code>mysql<span class="token operator">&gt;</span> select <span class="token operator">*</span> from t_product where id <span class="token operator">=</span> <span class="token number">1001</span><span class="token punctuation">;</span>
<span class="token operator">+</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">+</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">+</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">-</span><span class="token operator">+</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">-</span><span class="token operator">+</span>
<span class="token operator">|</span> id   <span class="token operator">|</span> t_pro_name <span class="token operator">|</span> t_pro_price <span class="token operator">|</span> t_pro_stock <span class="token operator">|</span>
<span class="token operator">+</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">+</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">+</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">-</span><span class="token operator">+</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">-</span><span class="token operator">+</span>
<span class="token operator">|</span> <span class="token number">1001</span> <span class="token operator">|</span> 华为       <span class="token operator">|</span>     <span class="token number">2399.00</span> <span class="token operator">|</span>          <span class="token number">90</span> <span class="token operator">|</span>
<span class="token operator">+</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">+</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">+</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">-</span><span class="token operator">+</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">--</span><span class="token operator">-</span><span class="token operator">+</span>
<span class="token number">1</span> row in set <span class="token punctuation">(</span><span class="token number">0.00</span> sec<span class="token punctuation">)</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br></div></div><p>可以看到，id为1001的商品库存由原来的100变更为90，减少了10个库存。</p> <p>（3）再次查询订单表和订单条目表中的数据，如下所示。</p> <ul><li>查询订单表</li></ul> <div class="language-sql line-numbers-mode"><pre class="language-sql"><code>mysql<span class="token operator">&gt;</span> <span class="token keyword">select</span> <span class="token operator">*</span> <span class="token keyword">from</span> t_order<span class="token punctuation">;</span>
<span class="token operator">+</span><span class="token comment">------------------+-----------+-------------+-------------+-----------+---------------+</span>
<span class="token operator">|</span> id               <span class="token operator">|</span> t_user_id <span class="token operator">|</span> t_user_name <span class="token operator">|</span> t_phone     <span class="token operator">|</span> t_address <span class="token operator">|</span> t_total_price <span class="token operator">|</span>
<span class="token operator">+</span><span class="token comment">------------------+-----------+-------------+-------------+-----------+---------------+</span>
<span class="token operator">|</span> <span class="token number">3270016896208896</span> <span class="token operator">|</span>      <span class="token number">1001</span> <span class="token operator">|</span> binghe      <span class="token operator">|</span> <span class="token number">13212345678</span> <span class="token operator">|</span> 北京      <span class="token operator">|</span>      <span class="token number">23990.00</span> <span class="token operator">|</span>
<span class="token operator">+</span><span class="token comment">------------------+-----------+-------------+-------------+-----------+---------------+</span>
<span class="token number">1</span> <span class="token keyword">row</span> <span class="token operator">in</span> <span class="token keyword">set</span> <span class="token punctuation">(</span><span class="token number">0.00</span> sec<span class="token punctuation">)</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br></div></div><p>可以看到，订单数据表中成功记录了订单的信息</p> <ul><li>查询订单条目表</li></ul> <div class="language-sql line-numbers-mode"><pre class="language-sql"><code>mysql<span class="token operator">&gt;</span> <span class="token keyword">select</span> <span class="token operator">*</span> <span class="token keyword">from</span> t_order_item<span class="token punctuation">;</span>
<span class="token operator">+</span><span class="token comment">------------------+------------------+----------+------------+-------------+----------+</span>
<span class="token operator">|</span> id               <span class="token operator">|</span> t_order_id       <span class="token operator">|</span> t_pro_id <span class="token operator">|</span> t_pro_name <span class="token operator">|</span> t_pro_price <span class="token operator">|</span> t_number <span class="token operator">|</span>
<span class="token operator">+</span><span class="token comment">------------------+------------------+----------+------------+-------------+----------+</span>
<span class="token operator">|</span> <span class="token number">3270017277890560</span> <span class="token operator">|</span> <span class="token number">3270016896208896</span> <span class="token operator">|</span>     <span class="token number">1001</span> <span class="token operator">|</span> 华为       <span class="token operator">|</span>     <span class="token number">2399.00</span> <span class="token operator">|</span>       <span class="token number">10</span> <span class="token operator">|</span>
<span class="token operator">+</span><span class="token comment">------------------+------------------+----------+------------+-------------+----------+</span>
<span class="token number">1</span> <span class="token keyword">row</span> <span class="token operator">in</span> <span class="token keyword">set</span> <span class="token punctuation">(</span><span class="token number">0.00</span> sec<span class="token punctuation">)</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br></div></div><p>可以看到，订单条目数据表中成功记录了订单条目的信息。</p> <p>至此，项目的测试完毕。</p> <p>另外，小伙伴们在【冰河技术】知识星球获取到源码后，可以自行测试其他异常情况，比如商品不存在的异常和用户不存在的异常，或者自行验证几个其他的异常情况，看提交是否提交，商品库存是否扣减了。</p> <p>这次，我们只是使用SpringBoot快速搭建了三个微服务项目，从下一篇开始，我们就要逐渐接入SpringCloud Alibaba技术了，小伙伴们，你们准备好了吗？加入【冰河技术】知识星球，一起搞定《<a href="https://mp.weixin.qq.com/mp/appmsgalbum?__biz=Mzg4MjU0OTM1OA==&amp;action=getalbum&amp;album_id=2337104419664084992&amp;scene=173&amp;from_msgid=2247500214&amp;from_itemidx=1&amp;count=3&amp;nolastread=1#wechat_redirect" target="_blank" rel="noopener noreferrer">SpringCloud Alibaba实战<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a>》吧，加油！！</p> <h2 id="关于星球"><a href="#关于星球" class="header-anchor">#</a> 关于星球</h2> <p>最近，冰河创建了【冰河技术】知识星球，《<a href="https://mp.weixin.qq.com/mp/appmsgalbum?__biz=Mzg4MjU0OTM1OA==&amp;action=getalbum&amp;album_id=2337104419664084992&amp;scene=173&amp;from_msgid=2247500214&amp;from_itemidx=1&amp;count=3&amp;nolastread=1#wechat_redirect" target="_blank" rel="noopener noreferrer">SpringCloud Alibaba实战<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a>》专栏的源码获取方式会放到知识星期中，同时在微信上会创建专门的知识星球群，冰河会在知识星球上和星球群里解答球友的提问。</p> <h3 id="星球提供的服务"><a href="#星球提供的服务" class="header-anchor">#</a> 星球提供的服务</h3> <p>冰河整理了星球提供的一些服务，如下所示。</p> <p>加入星球，你将获得：</p> <p>1.学习SpringCloud Alibaba实战项目—从零开发微服务项目</p> <p>2.学习高并发、大流量业务场景的解决方案，体验大厂真正的高并发、大流量的业务场景</p> <p>3.学习进大厂必备技能：性能调优、并发编程、分布式、微服务、框架源码、中间件开发、项目实战</p> <p>4.提供站点 https://binghe001.github.io 所有学习内容的指导、帮助</p> <p>5.GitHub：https://github.com/binghe001/BingheGuide - 非常有价值的技术资料仓库，包括冰河所有的博客开放案例代码</p> <p>6.可以发送你的简历到我的邮箱，提供简历批阅服务</p> <p>7.提供技术问题、系统架构、学习成长、晋升答辩等各项内容的回答</p> <p>8.定期的整理和分享出各类专属星球的技术小册、电子书、编程视频、PDF文件</p> <p>9.定期组织技术直播分享，传道、授业、解惑，指导阶段瓶颈突破技巧</p> <h3 id="星球门票价格"><a href="#星球门票价格" class="header-anchor">#</a> 星球门票价格</h3> <p>星球目前的门票价格50元，随着每次加入新实战项目和分享硬核技术上调入场价格。</p> <p>最后，小伙伴们可以扫描或者长按下图中的二维码加入星球，也可以在 冰河技术 公众号回复“星球”，领取入场优惠券。</p> <p><img alt="sa-2022-04-21-007" data-src="https://binghe001.github.io/assets/images/microservices/springcloudalibaba/sa-2022-04-21-007.png" loading="lazy" class="lazy"></p> <p><strong>好了，今天就到这儿吧，我是冰河，我们下期见~~</strong></p> <h2 id="写在最后"><a href="#写在最后" class="header-anchor">#</a> 写在最后</h2> <blockquote><p>如果你觉得冰河写的还不错，请微信搜索并关注「 <strong>冰河技术</strong> 」微信公众号，跟冰河学习高并发、分布式、微服务、大数据、互联网和云原生技术，「 <strong>冰河技术</strong> 」微信公众号更新了大量技术专题，每一篇技术文章干货满满！不少读者已经通过阅读「 <strong>冰河技术</strong> 」微信公众号文章，吊打面试官，成功跳槽到大厂；也有不少读者实现了技术上的飞跃，成为公司的技术骨干！如果你也想像他们一样提升自己的能力，实现技术能力的飞跃，进大厂，升职加薪，那就关注「 <strong>冰河技术</strong> 」微信公众号吧，每天更新超硬核技术干货，让你对如何提升技术能力不再迷茫！</p></blockquote> <p><img alt="" data-src="https://img-blog.csdnimg.cn/20200906013715889.png" loading="lazy" class="lazy"></p></div> <footer class="page-edit"><div class="edit-link"><a href="https://github.com/binghe001/BingheGuide/edit/master/docs/md/microservices/springcloudalibaba/2022-04-21-SA实战-完成三大微服务的搭建与交互开发.md" target="_blank" rel="noopener noreferrer">在 GitHub 上编辑此页</a> <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></div> <div class="last-updated"><span class="prefix">上次更新: </span> <span class="time">2022/5/23</span></div></footer> <div class="page-nav"><p class="inner"><span class="prev">
        ←
        <a href="/md/microservices/springcloudalibaba/2022-04-18-SA实战-开撸-完成通用模块的开发.html" class="prev">
          SA实战 ·《SpringCloud Alibaba实战》开撸：完成通用模块的开发
        </a></span> <span class="next"><a href="/md/microservices/springcloudalibaba/2022-04-25-SA实战-服务治理-实现服务的注册与发现.html">
          SA实战 ·《SpringCloud Alibaba实战》服务治理：实现服务的自动注册与发现
        </a>
        →
      </span></p></div> </main></div> <aside class="page-sidebar"> <div class="page-side-toolbar"><div class="option-box-toc-fixed"><div class="toc-container-sidebar"><div class="pos-box"><div class="icon-arrow"></div> <div class="scroll-box" style="max-height:650px"><div style="font-weight:bold;text-align:center;">SA实战 ·《SpringCloud Alibaba实战》快速搭建三大微服务并完成交互开发与测试</div> <hr> <div class="toc-box"><ul class="toc-sidebar-links"><li><a href="/md/microservices/springcloudalibaba/2022-04-21-SA%E5%AE%9E%E6%88%98-%E5%AE%8C%E6%88%90%E4%B8%89%E5%A4%A7%E5%BE%AE%E6%9C%8D%E5%8A%A1%E7%9A%84%E6%90%AD%E5%BB%BA%E4%B8%8E%E4%BA%A4%E4%BA%92%E5%BC%80%E5%8F%91.html#文章结构" class="toc-sidebar-link">文章结构</a><ul class="toc-sidebar-sub-headers"></ul></li><li><a href="/md/microservices/springcloudalibaba/2022-04-21-SA%E5%AE%9E%E6%88%98-%E5%AE%8C%E6%88%90%E4%B8%89%E5%A4%A7%E5%BE%AE%E6%9C%8D%E5%8A%A1%E7%9A%84%E6%90%AD%E5%BB%BA%E4%B8%8E%E4%BA%A4%E4%BA%92%E5%BC%80%E5%8F%91.html#项目概述" class="toc-sidebar-link">项目概述</a><ul class="toc-sidebar-sub-headers"><li class="toc-sidebar-sub-header"><a href="/md/microservices/springcloudalibaba/2022-04-21-SA%E5%AE%9E%E6%88%98-%E5%AE%8C%E6%88%90%E4%B8%89%E5%A4%A7%E5%BE%AE%E6%9C%8D%E5%8A%A1%E7%9A%84%E6%90%AD%E5%BB%BA%E4%B8%8E%E4%BA%A4%E4%BA%92%E5%BC%80%E5%8F%91.html#整体交互流程" class="toc-sidebar-link">整体交互流程</a></li><li class="toc-sidebar-sub-header"><a href="/md/microservices/springcloudalibaba/2022-04-21-SA%E5%AE%9E%E6%88%98-%E5%AE%8C%E6%88%90%E4%B8%89%E5%A4%A7%E5%BE%AE%E6%9C%8D%E5%8A%A1%E7%9A%84%E6%90%AD%E5%BB%BA%E4%B8%8E%E4%BA%A4%E4%BA%92%E5%BC%80%E5%8F%91.html#服务规划" class="toc-sidebar-link">服务规划</a></li></ul></li><li><a href="/md/microservices/springcloudalibaba/2022-04-21-SA%E5%AE%9E%E6%88%98-%E5%AE%8C%E6%88%90%E4%B8%89%E5%A4%A7%E5%BE%AE%E6%9C%8D%E5%8A%A1%E7%9A%84%E6%90%AD%E5%BB%BA%E4%B8%8E%E4%BA%A4%E4%BA%92%E5%BC%80%E5%8F%91.html#用户微服务" class="toc-sidebar-link">用户微服务</a><ul class="toc-sidebar-sub-headers"><li class="toc-sidebar-sub-header"><a href="/md/microservices/springcloudalibaba/2022-04-21-SA%E5%AE%9E%E6%88%98-%E5%AE%8C%E6%88%90%E4%B8%89%E5%A4%A7%E5%BE%AE%E6%9C%8D%E5%8A%A1%E7%9A%84%E6%90%AD%E5%BB%BA%E4%B8%8E%E4%BA%A4%E4%BA%92%E5%BC%80%E5%8F%91.html#搭建项目" class="toc-sidebar-link">搭建项目</a></li><li class="toc-sidebar-sub-header"><a href="/md/microservices/springcloudalibaba/2022-04-21-SA%E5%AE%9E%E6%88%98-%E5%AE%8C%E6%88%90%E4%B8%89%E5%A4%A7%E5%BE%AE%E6%9C%8D%E5%8A%A1%E7%9A%84%E6%90%AD%E5%BB%BA%E4%B8%8E%E4%BA%A4%E4%BA%92%E5%BC%80%E5%8F%91.html#开发持久层" class="toc-sidebar-link">开发持久层</a></li><li class="toc-sidebar-sub-header"><a href="/md/microservices/springcloudalibaba/2022-04-21-SA%E5%AE%9E%E6%88%98-%E5%AE%8C%E6%88%90%E4%B8%89%E5%A4%A7%E5%BE%AE%E6%9C%8D%E5%8A%A1%E7%9A%84%E6%90%AD%E5%BB%BA%E4%B8%8E%E4%BA%A4%E4%BA%92%E5%BC%80%E5%8F%91.html#开发业务逻辑层" class="toc-sidebar-link">开发业务逻辑层</a></li><li class="toc-sidebar-sub-header"><a href="/md/microservices/springcloudalibaba/2022-04-21-SA%E5%AE%9E%E6%88%98-%E5%AE%8C%E6%88%90%E4%B8%89%E5%A4%A7%E5%BE%AE%E6%9C%8D%E5%8A%A1%E7%9A%84%E6%90%AD%E5%BB%BA%E4%B8%8E%E4%BA%A4%E4%BA%92%E5%BC%80%E5%8F%91.html#开发接口层" class="toc-sidebar-link">开发接口层</a></li><li class="toc-sidebar-sub-header"><a href="/md/microservices/springcloudalibaba/2022-04-21-SA%E5%AE%9E%E6%88%98-%E5%AE%8C%E6%88%90%E4%B8%89%E5%A4%A7%E5%BE%AE%E6%9C%8D%E5%8A%A1%E7%9A%84%E6%90%AD%E5%BB%BA%E4%B8%8E%E4%BA%A4%E4%BA%92%E5%BC%80%E5%8F%91.html#开发服务启动类" class="toc-sidebar-link">开发服务启动类</a></li></ul></li><li><a href="/md/microservices/springcloudalibaba/2022-04-21-SA%E5%AE%9E%E6%88%98-%E5%AE%8C%E6%88%90%E4%B8%89%E5%A4%A7%E5%BE%AE%E6%9C%8D%E5%8A%A1%E7%9A%84%E6%90%AD%E5%BB%BA%E4%B8%8E%E4%BA%A4%E4%BA%92%E5%BC%80%E5%8F%91.html#商品微服务" class="toc-sidebar-link">商品微服务</a><ul class="toc-sidebar-sub-headers"><li class="toc-sidebar-sub-header"><a href="/md/microservices/springcloudalibaba/2022-04-21-SA%E5%AE%9E%E6%88%98-%E5%AE%8C%E6%88%90%E4%B8%89%E5%A4%A7%E5%BE%AE%E6%9C%8D%E5%8A%A1%E7%9A%84%E6%90%AD%E5%BB%BA%E4%B8%8E%E4%BA%A4%E4%BA%92%E5%BC%80%E5%8F%91.html#项目搭建" class="toc-sidebar-link">项目搭建</a></li><li class="toc-sidebar-sub-header"><a href="/md/microservices/springcloudalibaba/2022-04-21-SA%E5%AE%9E%E6%88%98-%E5%AE%8C%E6%88%90%E4%B8%89%E5%A4%A7%E5%BE%AE%E6%9C%8D%E5%8A%A1%E7%9A%84%E6%90%AD%E5%BB%BA%E4%B8%8E%E4%BA%A4%E4%BA%92%E5%BC%80%E5%8F%91.html#开发持久层-2" class="toc-sidebar-link">开发持久层</a></li><li class="toc-sidebar-sub-header"><a href="/md/microservices/springcloudalibaba/2022-04-21-SA%E5%AE%9E%E6%88%98-%E5%AE%8C%E6%88%90%E4%B8%89%E5%A4%A7%E5%BE%AE%E6%9C%8D%E5%8A%A1%E7%9A%84%E6%90%AD%E5%BB%BA%E4%B8%8E%E4%BA%A4%E4%BA%92%E5%BC%80%E5%8F%91.html#开发业务逻辑层-2" class="toc-sidebar-link">开发业务逻辑层</a></li><li class="toc-sidebar-sub-header"><a href="/md/microservices/springcloudalibaba/2022-04-21-SA%E5%AE%9E%E6%88%98-%E5%AE%8C%E6%88%90%E4%B8%89%E5%A4%A7%E5%BE%AE%E6%9C%8D%E5%8A%A1%E7%9A%84%E6%90%AD%E5%BB%BA%E4%B8%8E%E4%BA%A4%E4%BA%92%E5%BC%80%E5%8F%91.html#开发接口层-2" class="toc-sidebar-link">开发接口层</a></li><li class="toc-sidebar-sub-header"><a href="/md/microservices/springcloudalibaba/2022-04-21-SA%E5%AE%9E%E6%88%98-%E5%AE%8C%E6%88%90%E4%B8%89%E5%A4%A7%E5%BE%AE%E6%9C%8D%E5%8A%A1%E7%9A%84%E6%90%AD%E5%BB%BA%E4%B8%8E%E4%BA%A4%E4%BA%92%E5%BC%80%E5%8F%91.html#开发服务启动类-2" class="toc-sidebar-link">开发服务启动类</a></li></ul></li><li><a href="/md/microservices/springcloudalibaba/2022-04-21-SA%E5%AE%9E%E6%88%98-%E5%AE%8C%E6%88%90%E4%B8%89%E5%A4%A7%E5%BE%AE%E6%9C%8D%E5%8A%A1%E7%9A%84%E6%90%AD%E5%BB%BA%E4%B8%8E%E4%BA%A4%E4%BA%92%E5%BC%80%E5%8F%91.html#订单微服务" class="toc-sidebar-link">订单微服务</a><ul class="toc-sidebar-sub-headers"><li class="toc-sidebar-sub-header"><a href="/md/microservices/springcloudalibaba/2022-04-21-SA%E5%AE%9E%E6%88%98-%E5%AE%8C%E6%88%90%E4%B8%89%E5%A4%A7%E5%BE%AE%E6%9C%8D%E5%8A%A1%E7%9A%84%E6%90%AD%E5%BB%BA%E4%B8%8E%E4%BA%A4%E4%BA%92%E5%BC%80%E5%8F%91.html#项目搭建-2" class="toc-sidebar-link">项目搭建</a></li><li class="toc-sidebar-sub-header"><a href="/md/microservices/springcloudalibaba/2022-04-21-SA%E5%AE%9E%E6%88%98-%E5%AE%8C%E6%88%90%E4%B8%89%E5%A4%A7%E5%BE%AE%E6%9C%8D%E5%8A%A1%E7%9A%84%E6%90%AD%E5%BB%BA%E4%B8%8E%E4%BA%A4%E4%BA%92%E5%BC%80%E5%8F%91.html#开发持久层-3" class="toc-sidebar-link">开发持久层</a></li><li class="toc-sidebar-sub-header"><a href="/md/microservices/springcloudalibaba/2022-04-21-SA%E5%AE%9E%E6%88%98-%E5%AE%8C%E6%88%90%E4%B8%89%E5%A4%A7%E5%BE%AE%E6%9C%8D%E5%8A%A1%E7%9A%84%E6%90%AD%E5%BB%BA%E4%B8%8E%E4%BA%A4%E4%BA%92%E5%BC%80%E5%8F%91.html#开发业务逻辑层-3" class="toc-sidebar-link">开发业务逻辑层</a></li><li class="toc-sidebar-sub-header"><a href="/md/microservices/springcloudalibaba/2022-04-21-SA%E5%AE%9E%E6%88%98-%E5%AE%8C%E6%88%90%E4%B8%89%E5%A4%A7%E5%BE%AE%E6%9C%8D%E5%8A%A1%E7%9A%84%E6%90%AD%E5%BB%BA%E4%B8%8E%E4%BA%A4%E4%BA%92%E5%BC%80%E5%8F%91.html#开发接口层-3" class="toc-sidebar-link">开发接口层</a></li><li class="toc-sidebar-sub-header"><a href="/md/microservices/springcloudalibaba/2022-04-21-SA%E5%AE%9E%E6%88%98-%E5%AE%8C%E6%88%90%E4%B8%89%E5%A4%A7%E5%BE%AE%E6%9C%8D%E5%8A%A1%E7%9A%84%E6%90%AD%E5%BB%BA%E4%B8%8E%E4%BA%A4%E4%BA%92%E5%BC%80%E5%8F%91.html#开发服务启动类-3" class="toc-sidebar-link">开发服务启动类</a></li><li class="toc-sidebar-sub-header"><a href="/md/microservices/springcloudalibaba/2022-04-21-SA%E5%AE%9E%E6%88%98-%E5%AE%8C%E6%88%90%E4%B8%89%E5%A4%A7%E5%BE%AE%E6%9C%8D%E5%8A%A1%E7%9A%84%E6%90%AD%E5%BB%BA%E4%B8%8E%E4%BA%A4%E4%BA%92%E5%BC%80%E5%8F%91.html#开发辅助类" class="toc-sidebar-link">开发辅助类</a></li></ul></li><li><a href="/md/microservices/springcloudalibaba/2022-04-21-SA%E5%AE%9E%E6%88%98-%E5%AE%8C%E6%88%90%E4%B8%89%E5%A4%A7%E5%BE%AE%E6%9C%8D%E5%8A%A1%E7%9A%84%E6%90%AD%E5%BB%BA%E4%B8%8E%E4%BA%A4%E4%BA%92%E5%BC%80%E5%8F%91.html#测试项目" class="toc-sidebar-link">测试项目</a><ul class="toc-sidebar-sub-headers"><li class="toc-sidebar-sub-header"><a href="/md/microservices/springcloudalibaba/2022-04-21-SA%E5%AE%9E%E6%88%98-%E5%AE%8C%E6%88%90%E4%B8%89%E5%A4%A7%E5%BE%AE%E6%9C%8D%E5%8A%A1%E7%9A%84%E6%90%AD%E5%BB%BA%E4%B8%8E%E4%BA%A4%E4%BA%92%E5%BC%80%E5%8F%91.html#添加测试数据" class="toc-sidebar-link">添加测试数据</a></li><li class="toc-sidebar-sub-header"><a href="/md/microservices/springcloudalibaba/2022-04-21-SA%E5%AE%9E%E6%88%98-%E5%AE%8C%E6%88%90%E4%B8%89%E5%A4%A7%E5%BE%AE%E6%9C%8D%E5%8A%A1%E7%9A%84%E6%90%AD%E5%BB%BA%E4%B8%8E%E4%BA%A4%E4%BA%92%E5%BC%80%E5%8F%91.html#测试库存不足的情况" class="toc-sidebar-link">测试库存不足的情况</a></li><li class="toc-sidebar-sub-header"><a href="/md/microservices/springcloudalibaba/2022-04-21-SA%E5%AE%9E%E6%88%98-%E5%AE%8C%E6%88%90%E4%B8%89%E5%A4%A7%E5%BE%AE%E6%9C%8D%E5%8A%A1%E7%9A%84%E6%90%AD%E5%BB%BA%E4%B8%8E%E4%BA%A4%E4%BA%92%E5%BC%80%E5%8F%91.html#测试正常下单的情况" class="toc-sidebar-link">测试正常下单的情况</a></li></ul></li><li><a href="/md/microservices/springcloudalibaba/2022-04-21-SA%E5%AE%9E%E6%88%98-%E5%AE%8C%E6%88%90%E4%B8%89%E5%A4%A7%E5%BE%AE%E6%9C%8D%E5%8A%A1%E7%9A%84%E6%90%AD%E5%BB%BA%E4%B8%8E%E4%BA%A4%E4%BA%92%E5%BC%80%E5%8F%91.html#关于星球" class="toc-sidebar-link">关于星球</a><ul class="toc-sidebar-sub-headers"><li class="toc-sidebar-sub-header"><a href="/md/microservices/springcloudalibaba/2022-04-21-SA%E5%AE%9E%E6%88%98-%E5%AE%8C%E6%88%90%E4%B8%89%E5%A4%A7%E5%BE%AE%E6%9C%8D%E5%8A%A1%E7%9A%84%E6%90%AD%E5%BB%BA%E4%B8%8E%E4%BA%A4%E4%BA%92%E5%BC%80%E5%8F%91.html#星球提供的服务" class="toc-sidebar-link">星球提供的服务</a></li><li class="toc-sidebar-sub-header"><a href="/md/microservices/springcloudalibaba/2022-04-21-SA%E5%AE%9E%E6%88%98-%E5%AE%8C%E6%88%90%E4%B8%89%E5%A4%A7%E5%BE%AE%E6%9C%8D%E5%8A%A1%E7%9A%84%E6%90%AD%E5%BB%BA%E4%B8%8E%E4%BA%A4%E4%BA%92%E5%BC%80%E5%8F%91.html#星球门票价格" class="toc-sidebar-link">星球门票价格</a></li></ul></li><li><a href="/md/microservices/springcloudalibaba/2022-04-21-SA%E5%AE%9E%E6%88%98-%E5%AE%8C%E6%88%90%E4%B8%89%E5%A4%A7%E5%BE%AE%E6%9C%8D%E5%8A%A1%E7%9A%84%E6%90%AD%E5%BB%BA%E4%B8%8E%E4%BA%A4%E4%BA%92%E5%BC%80%E5%8F%91.html#写在最后" class="toc-sidebar-link">写在最后</a><ul class="toc-sidebar-sub-headers"></ul></li></ul></div></div></div></div></div> <div class="option-box-toc-over"><img src="/images/system/toc.png" class="nozoom"> <span class="show-txt">目录</span> <div class="toc-container"><div class="pos-box"><div class="icon-arrow"></div> <div class="scroll-box" style="max-height:550px"><div style="font-weight:bold;text-align:center;">SA实战 ·《SpringCloud Alibaba实战》快速搭建三大微服务并完成交互开发与测试</div> <hr> <div class="toc-box"><ul class="toc-sidebar-links"><li><a href="/md/microservices/springcloudalibaba/2022-04-21-SA%E5%AE%9E%E6%88%98-%E5%AE%8C%E6%88%90%E4%B8%89%E5%A4%A7%E5%BE%AE%E6%9C%8D%E5%8A%A1%E7%9A%84%E6%90%AD%E5%BB%BA%E4%B8%8E%E4%BA%A4%E4%BA%92%E5%BC%80%E5%8F%91.html#文章结构" class="toc-sidebar-link">文章结构</a><ul class="toc-sidebar-sub-headers"></ul></li><li><a href="/md/microservices/springcloudalibaba/2022-04-21-SA%E5%AE%9E%E6%88%98-%E5%AE%8C%E6%88%90%E4%B8%89%E5%A4%A7%E5%BE%AE%E6%9C%8D%E5%8A%A1%E7%9A%84%E6%90%AD%E5%BB%BA%E4%B8%8E%E4%BA%A4%E4%BA%92%E5%BC%80%E5%8F%91.html#项目概述" class="toc-sidebar-link">项目概述</a><ul class="toc-sidebar-sub-headers"><li class="toc-sidebar-sub-header"><a href="/md/microservices/springcloudalibaba/2022-04-21-SA%E5%AE%9E%E6%88%98-%E5%AE%8C%E6%88%90%E4%B8%89%E5%A4%A7%E5%BE%AE%E6%9C%8D%E5%8A%A1%E7%9A%84%E6%90%AD%E5%BB%BA%E4%B8%8E%E4%BA%A4%E4%BA%92%E5%BC%80%E5%8F%91.html#整体交互流程" class="toc-sidebar-link">整体交互流程</a></li><li class="toc-sidebar-sub-header"><a href="/md/microservices/springcloudalibaba/2022-04-21-SA%E5%AE%9E%E6%88%98-%E5%AE%8C%E6%88%90%E4%B8%89%E5%A4%A7%E5%BE%AE%E6%9C%8D%E5%8A%A1%E7%9A%84%E6%90%AD%E5%BB%BA%E4%B8%8E%E4%BA%A4%E4%BA%92%E5%BC%80%E5%8F%91.html#服务规划" class="toc-sidebar-link">服务规划</a></li></ul></li><li><a href="/md/microservices/springcloudalibaba/2022-04-21-SA%E5%AE%9E%E6%88%98-%E5%AE%8C%E6%88%90%E4%B8%89%E5%A4%A7%E5%BE%AE%E6%9C%8D%E5%8A%A1%E7%9A%84%E6%90%AD%E5%BB%BA%E4%B8%8E%E4%BA%A4%E4%BA%92%E5%BC%80%E5%8F%91.html#用户微服务" class="toc-sidebar-link">用户微服务</a><ul class="toc-sidebar-sub-headers"><li class="toc-sidebar-sub-header"><a href="/md/microservices/springcloudalibaba/2022-04-21-SA%E5%AE%9E%E6%88%98-%E5%AE%8C%E6%88%90%E4%B8%89%E5%A4%A7%E5%BE%AE%E6%9C%8D%E5%8A%A1%E7%9A%84%E6%90%AD%E5%BB%BA%E4%B8%8E%E4%BA%A4%E4%BA%92%E5%BC%80%E5%8F%91.html#搭建项目" class="toc-sidebar-link">搭建项目</a></li><li class="toc-sidebar-sub-header"><a href="/md/microservices/springcloudalibaba/2022-04-21-SA%E5%AE%9E%E6%88%98-%E5%AE%8C%E6%88%90%E4%B8%89%E5%A4%A7%E5%BE%AE%E6%9C%8D%E5%8A%A1%E7%9A%84%E6%90%AD%E5%BB%BA%E4%B8%8E%E4%BA%A4%E4%BA%92%E5%BC%80%E5%8F%91.html#开发持久层" class="toc-sidebar-link">开发持久层</a></li><li class="toc-sidebar-sub-header"><a href="/md/microservices/springcloudalibaba/2022-04-21-SA%E5%AE%9E%E6%88%98-%E5%AE%8C%E6%88%90%E4%B8%89%E5%A4%A7%E5%BE%AE%E6%9C%8D%E5%8A%A1%E7%9A%84%E6%90%AD%E5%BB%BA%E4%B8%8E%E4%BA%A4%E4%BA%92%E5%BC%80%E5%8F%91.html#开发业务逻辑层" class="toc-sidebar-link">开发业务逻辑层</a></li><li class="toc-sidebar-sub-header"><a href="/md/microservices/springcloudalibaba/2022-04-21-SA%E5%AE%9E%E6%88%98-%E5%AE%8C%E6%88%90%E4%B8%89%E5%A4%A7%E5%BE%AE%E6%9C%8D%E5%8A%A1%E7%9A%84%E6%90%AD%E5%BB%BA%E4%B8%8E%E4%BA%A4%E4%BA%92%E5%BC%80%E5%8F%91.html#开发接口层" class="toc-sidebar-link">开发接口层</a></li><li class="toc-sidebar-sub-header"><a href="/md/microservices/springcloudalibaba/2022-04-21-SA%E5%AE%9E%E6%88%98-%E5%AE%8C%E6%88%90%E4%B8%89%E5%A4%A7%E5%BE%AE%E6%9C%8D%E5%8A%A1%E7%9A%84%E6%90%AD%E5%BB%BA%E4%B8%8E%E4%BA%A4%E4%BA%92%E5%BC%80%E5%8F%91.html#开发服务启动类" class="toc-sidebar-link">开发服务启动类</a></li></ul></li><li><a href="/md/microservices/springcloudalibaba/2022-04-21-SA%E5%AE%9E%E6%88%98-%E5%AE%8C%E6%88%90%E4%B8%89%E5%A4%A7%E5%BE%AE%E6%9C%8D%E5%8A%A1%E7%9A%84%E6%90%AD%E5%BB%BA%E4%B8%8E%E4%BA%A4%E4%BA%92%E5%BC%80%E5%8F%91.html#商品微服务" class="toc-sidebar-link">商品微服务</a><ul class="toc-sidebar-sub-headers"><li class="toc-sidebar-sub-header"><a href="/md/microservices/springcloudalibaba/2022-04-21-SA%E5%AE%9E%E6%88%98-%E5%AE%8C%E6%88%90%E4%B8%89%E5%A4%A7%E5%BE%AE%E6%9C%8D%E5%8A%A1%E7%9A%84%E6%90%AD%E5%BB%BA%E4%B8%8E%E4%BA%A4%E4%BA%92%E5%BC%80%E5%8F%91.html#项目搭建" class="toc-sidebar-link">项目搭建</a></li><li class="toc-sidebar-sub-header"><a href="/md/microservices/springcloudalibaba/2022-04-21-SA%E5%AE%9E%E6%88%98-%E5%AE%8C%E6%88%90%E4%B8%89%E5%A4%A7%E5%BE%AE%E6%9C%8D%E5%8A%A1%E7%9A%84%E6%90%AD%E5%BB%BA%E4%B8%8E%E4%BA%A4%E4%BA%92%E5%BC%80%E5%8F%91.html#开发持久层-2" class="toc-sidebar-link">开发持久层</a></li><li class="toc-sidebar-sub-header"><a href="/md/microservices/springcloudalibaba/2022-04-21-SA%E5%AE%9E%E6%88%98-%E5%AE%8C%E6%88%90%E4%B8%89%E5%A4%A7%E5%BE%AE%E6%9C%8D%E5%8A%A1%E7%9A%84%E6%90%AD%E5%BB%BA%E4%B8%8E%E4%BA%A4%E4%BA%92%E5%BC%80%E5%8F%91.html#开发业务逻辑层-2" class="toc-sidebar-link">开发业务逻辑层</a></li><li class="toc-sidebar-sub-header"><a href="/md/microservices/springcloudalibaba/2022-04-21-SA%E5%AE%9E%E6%88%98-%E5%AE%8C%E6%88%90%E4%B8%89%E5%A4%A7%E5%BE%AE%E6%9C%8D%E5%8A%A1%E7%9A%84%E6%90%AD%E5%BB%BA%E4%B8%8E%E4%BA%A4%E4%BA%92%E5%BC%80%E5%8F%91.html#开发接口层-2" class="toc-sidebar-link">开发接口层</a></li><li class="toc-sidebar-sub-header"><a href="/md/microservices/springcloudalibaba/2022-04-21-SA%E5%AE%9E%E6%88%98-%E5%AE%8C%E6%88%90%E4%B8%89%E5%A4%A7%E5%BE%AE%E6%9C%8D%E5%8A%A1%E7%9A%84%E6%90%AD%E5%BB%BA%E4%B8%8E%E4%BA%A4%E4%BA%92%E5%BC%80%E5%8F%91.html#开发服务启动类-2" class="toc-sidebar-link">开发服务启动类</a></li></ul></li><li><a href="/md/microservices/springcloudalibaba/2022-04-21-SA%E5%AE%9E%E6%88%98-%E5%AE%8C%E6%88%90%E4%B8%89%E5%A4%A7%E5%BE%AE%E6%9C%8D%E5%8A%A1%E7%9A%84%E6%90%AD%E5%BB%BA%E4%B8%8E%E4%BA%A4%E4%BA%92%E5%BC%80%E5%8F%91.html#订单微服务" class="toc-sidebar-link">订单微服务</a><ul class="toc-sidebar-sub-headers"><li class="toc-sidebar-sub-header"><a href="/md/microservices/springcloudalibaba/2022-04-21-SA%E5%AE%9E%E6%88%98-%E5%AE%8C%E6%88%90%E4%B8%89%E5%A4%A7%E5%BE%AE%E6%9C%8D%E5%8A%A1%E7%9A%84%E6%90%AD%E5%BB%BA%E4%B8%8E%E4%BA%A4%E4%BA%92%E5%BC%80%E5%8F%91.html#项目搭建-2" class="toc-sidebar-link">项目搭建</a></li><li class="toc-sidebar-sub-header"><a href="/md/microservices/springcloudalibaba/2022-04-21-SA%E5%AE%9E%E6%88%98-%E5%AE%8C%E6%88%90%E4%B8%89%E5%A4%A7%E5%BE%AE%E6%9C%8D%E5%8A%A1%E7%9A%84%E6%90%AD%E5%BB%BA%E4%B8%8E%E4%BA%A4%E4%BA%92%E5%BC%80%E5%8F%91.html#开发持久层-3" class="toc-sidebar-link">开发持久层</a></li><li class="toc-sidebar-sub-header"><a href="/md/microservices/springcloudalibaba/2022-04-21-SA%E5%AE%9E%E6%88%98-%E5%AE%8C%E6%88%90%E4%B8%89%E5%A4%A7%E5%BE%AE%E6%9C%8D%E5%8A%A1%E7%9A%84%E6%90%AD%E5%BB%BA%E4%B8%8E%E4%BA%A4%E4%BA%92%E5%BC%80%E5%8F%91.html#开发业务逻辑层-3" class="toc-sidebar-link">开发业务逻辑层</a></li><li class="toc-sidebar-sub-header"><a href="/md/microservices/springcloudalibaba/2022-04-21-SA%E5%AE%9E%E6%88%98-%E5%AE%8C%E6%88%90%E4%B8%89%E5%A4%A7%E5%BE%AE%E6%9C%8D%E5%8A%A1%E7%9A%84%E6%90%AD%E5%BB%BA%E4%B8%8E%E4%BA%A4%E4%BA%92%E5%BC%80%E5%8F%91.html#开发接口层-3" class="toc-sidebar-link">开发接口层</a></li><li class="toc-sidebar-sub-header"><a href="/md/microservices/springcloudalibaba/2022-04-21-SA%E5%AE%9E%E6%88%98-%E5%AE%8C%E6%88%90%E4%B8%89%E5%A4%A7%E5%BE%AE%E6%9C%8D%E5%8A%A1%E7%9A%84%E6%90%AD%E5%BB%BA%E4%B8%8E%E4%BA%A4%E4%BA%92%E5%BC%80%E5%8F%91.html#开发服务启动类-3" class="toc-sidebar-link">开发服务启动类</a></li><li class="toc-sidebar-sub-header"><a href="/md/microservices/springcloudalibaba/2022-04-21-SA%E5%AE%9E%E6%88%98-%E5%AE%8C%E6%88%90%E4%B8%89%E5%A4%A7%E5%BE%AE%E6%9C%8D%E5%8A%A1%E7%9A%84%E6%90%AD%E5%BB%BA%E4%B8%8E%E4%BA%A4%E4%BA%92%E5%BC%80%E5%8F%91.html#开发辅助类" class="toc-sidebar-link">开发辅助类</a></li></ul></li><li><a href="/md/microservices/springcloudalibaba/2022-04-21-SA%E5%AE%9E%E6%88%98-%E5%AE%8C%E6%88%90%E4%B8%89%E5%A4%A7%E5%BE%AE%E6%9C%8D%E5%8A%A1%E7%9A%84%E6%90%AD%E5%BB%BA%E4%B8%8E%E4%BA%A4%E4%BA%92%E5%BC%80%E5%8F%91.html#测试项目" class="toc-sidebar-link">测试项目</a><ul class="toc-sidebar-sub-headers"><li class="toc-sidebar-sub-header"><a href="/md/microservices/springcloudalibaba/2022-04-21-SA%E5%AE%9E%E6%88%98-%E5%AE%8C%E6%88%90%E4%B8%89%E5%A4%A7%E5%BE%AE%E6%9C%8D%E5%8A%A1%E7%9A%84%E6%90%AD%E5%BB%BA%E4%B8%8E%E4%BA%A4%E4%BA%92%E5%BC%80%E5%8F%91.html#添加测试数据" class="toc-sidebar-link">添加测试数据</a></li><li class="toc-sidebar-sub-header"><a href="/md/microservices/springcloudalibaba/2022-04-21-SA%E5%AE%9E%E6%88%98-%E5%AE%8C%E6%88%90%E4%B8%89%E5%A4%A7%E5%BE%AE%E6%9C%8D%E5%8A%A1%E7%9A%84%E6%90%AD%E5%BB%BA%E4%B8%8E%E4%BA%A4%E4%BA%92%E5%BC%80%E5%8F%91.html#测试库存不足的情况" class="toc-sidebar-link">测试库存不足的情况</a></li><li class="toc-sidebar-sub-header"><a href="/md/microservices/springcloudalibaba/2022-04-21-SA%E5%AE%9E%E6%88%98-%E5%AE%8C%E6%88%90%E4%B8%89%E5%A4%A7%E5%BE%AE%E6%9C%8D%E5%8A%A1%E7%9A%84%E6%90%AD%E5%BB%BA%E4%B8%8E%E4%BA%A4%E4%BA%92%E5%BC%80%E5%8F%91.html#测试正常下单的情况" class="toc-sidebar-link">测试正常下单的情况</a></li></ul></li><li><a href="/md/microservices/springcloudalibaba/2022-04-21-SA%E5%AE%9E%E6%88%98-%E5%AE%8C%E6%88%90%E4%B8%89%E5%A4%A7%E5%BE%AE%E6%9C%8D%E5%8A%A1%E7%9A%84%E6%90%AD%E5%BB%BA%E4%B8%8E%E4%BA%A4%E4%BA%92%E5%BC%80%E5%8F%91.html#关于星球" class="toc-sidebar-link">关于星球</a><ul class="toc-sidebar-sub-headers"><li class="toc-sidebar-sub-header"><a href="/md/microservices/springcloudalibaba/2022-04-21-SA%E5%AE%9E%E6%88%98-%E5%AE%8C%E6%88%90%E4%B8%89%E5%A4%A7%E5%BE%AE%E6%9C%8D%E5%8A%A1%E7%9A%84%E6%90%AD%E5%BB%BA%E4%B8%8E%E4%BA%A4%E4%BA%92%E5%BC%80%E5%8F%91.html#星球提供的服务" class="toc-sidebar-link">星球提供的服务</a></li><li class="toc-sidebar-sub-header"><a href="/md/microservices/springcloudalibaba/2022-04-21-SA%E5%AE%9E%E6%88%98-%E5%AE%8C%E6%88%90%E4%B8%89%E5%A4%A7%E5%BE%AE%E6%9C%8D%E5%8A%A1%E7%9A%84%E6%90%AD%E5%BB%BA%E4%B8%8E%E4%BA%A4%E4%BA%92%E5%BC%80%E5%8F%91.html#星球门票价格" class="toc-sidebar-link">星球门票价格</a></li></ul></li><li><a href="/md/microservices/springcloudalibaba/2022-04-21-SA%E5%AE%9E%E6%88%98-%E5%AE%8C%E6%88%90%E4%B8%89%E5%A4%A7%E5%BE%AE%E6%9C%8D%E5%8A%A1%E7%9A%84%E6%90%AD%E5%BB%BA%E4%B8%8E%E4%BA%A4%E4%BA%92%E5%BC%80%E5%8F%91.html#写在最后" class="toc-sidebar-link">写在最后</a><ul class="toc-sidebar-sub-headers"></ul></li></ul></div></div></div></div></div> <div class="option-box"><img src="/images/system/wechat.png" class="nozoom"> <span class="show-txt">手机看</span> <div class="toc-container"><div class="pos-box"><div class="icon-arrow"></div> <div class="scroll-box" style="text-align:center"><span style="font-size:0.9rem">微信扫一扫</span> <img height="180px" src="https://api.qrserver.com/v1/create-qr-code/?data=https://binghe001.github.io/md/microservices/springcloudalibaba/2022-04-21-SA%E5%AE%9E%E6%88%98-%E5%AE%8C%E6%88%90%E4%B8%89%E5%A4%A7%E5%BE%AE%E6%9C%8D%E5%8A%A1%E7%9A%84%E6%90%AD%E5%BB%BA%E4%B8%8E%E4%BA%A4%E4%BA%92%E5%BC%80%E5%8F%91.html" style="margin:10px;">
                可以<b>手机看</b>或分享至<b>朋友圈</b></div></div></div></div> <div class="option-box"><img src="/images/system/toggle.png" width="30px" class="nozoom"> <span class="show-txt">左栏</span></div> <div class="option-box"><img src="/images/system/xingqiu.png" width="25px" class="nozoom"> <span class="show-txt">星球</span> <div class="toc-container"><div class="pos-box"><div class="icon-arrow"></div> <div class="scroll-box" style="text-align:center"><span style="font-size:0.8rem;font-weight:bold;">实战项目<span style="font-size:8px;color:red;">「SpringCloud Alibaba实战项目」</span>、专属电子书、问题解答、简历指导、技术分享、晋升指导、视频课程</span> <img height="180px" src="/images/personal/xingqiu.png" style="margin:10px;"> <b>知识星球</b>：冰河技术
            </div></div></div></div> <div class="option-box"><img src="/images/system/wexin4.png" width="25px" class="nozoom"> <span class="show-txt">读者群</span> <div class="toc-container"><div class="pos-box"><div class="icon-arrow"></div> <div class="scroll-box" style="text-align:center"><span style="font-size:0.8rem;font-weight:bold;">添加冰河微信<span style="color:red;">(hacker_binghe)</span>进冰河技术学习交流圈「无任何套路」</span> <img src="/images/personal/hacker_binghe.jpg" height="180px" style="margin:10px;">
                PS：添加时请备注<b>读者加群</b>，谢谢！
              </div></div></div></div> <div class="option-box"><img src="/images/system/download-2.png" width="25px" class="nozoom"> <span class="show-txt">下资料</span> <div class="toc-container"><div class="pos-box"><div class="icon-arrow"></div> <div class="scroll-box" style="text-align:center"><span style="font-size:0.8rem;font-weight:bold;">扫描公众号，回复<span style="color:red;">“1024”</span>下载<span style="color:red;">100GB+</span>学习技术资料、PDF书籍、实战项目、简历模板等「无任何套路」</span> <img src="/images/personal/qrcode.png" height="180px" style="margin:10px;"> <b>公众号:</b> 冰河技术
              </div></div></div></div> <div class="option-box"><img src="/images/system/heart-1.png" width="25px" class="nozoom"> <span class="show-txt">赞赏我</span> <div class="toc-container"><div class="pos-box"><div class="icon-arrow"></div> <div class="scroll-box" style="text-align:center"><span style="font-size:0.8rem;font-weight:bold;">鼓励/支持/赞赏我</span> <img height="180px" src="/images/personal/encourage-head.png" style="margin:5px;"> <br>1. 不靠它生存但仍希望得到你的鼓励；
                <br>2. 时刻警醒自己保持技术人的初心；
              </div></div></div></div> <div title="SA实战 ·《SpringCloud Alibaba实战》开撸：完成通用模块的开发" class="option-box" style="padding-left:2px;text-align:center;"><a href="/md/microservices/springcloudalibaba/2022-04-18-SA实战-开撸-完成通用模块的开发.html"><img src="/images/system/pre2.png" width="30px" class="nozoom"> <span class="show-txt">上一篇</span></a></div> <div title="SA实战 ·《SpringCloud Alibaba实战》服务治理：实现服务的自动注册与发现" class="option-box" style="padding-left:2px;text-align:center;"><a href="/md/microservices/springcloudalibaba/2022-04-25-SA实战-服务治理-实现服务的注册与发现.html"><img src="/images/system/next2.png" width="30px" class="nozoom"> <span class="show-txt">下一篇</span></a></div></div>  <!----> </aside></div><div class="global-ui"><div class="read-more-wrap" style="display:none;position:absolute;bottom:0px;z-index:9999;width:100%;margin-top:-100px;font-family:PingFangSC-Regular, sans-serif;"><div id="read-more-mask" style="position: relative; height: 200px; background: -webkit-gradient(linear, 0 0%, 0 100%, from(rgba(255, 255, 255, 0)), to(rgb(255, 255, 255)));"></div> <a id="read-more-btn" target="_self" style="position: absolute; left: 50%; top: 70%; bottom: 30px; transform: translate(-50%, -50%); width: 160px; height: 36px; line-height: 36px; font-size: 15px; text-align: center; border: 1px solid rgb(222, 104, 109); color: rgb(222, 104, 109); background: rgb(255, 255, 255); cursor: pointer; border-radius: 6px;">阅读全文</a> <div id="btw-modal-wrap" style="display: none;"><div id="btw-mask" style="position: fixed; top: 0px; right: 0px; bottom: 0px; left: 0px; opacity: 0.7; z-index: 999; background: rgb(0, 0, 0);"></div> <div id="btw-modal" style="position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); width: 300px; text-align: center; font-size: 13px; background: rgb(255, 255, 255); border-radius: 10px; z-index: 9999; font-family: PingFangSC-Regular, sans-serif;"><span id="btw-modal-close-btn" style="position: absolute; top: 5px; right: 15px; line-height: 34px; font-size: 34px; cursor: pointer; opacity: 0.2; z-index: 9999; color: rgb(0, 0, 0); background: none; border: none; outline: none;">×</span> <p id="btw-modal-header" style="margin-top: 40px; line-height: 1.8; font-size: 13px;">
                扫码或搜索：<span style="color: #E9405A; font-weight: bold;">冰河技术</span> <br>发送：<span id="fustack-token" class="token" style="color: #e9415a; font-weight: bold; font-size: 17px; margin-bottom: 45px;">290992</span> <br>即可<span style="color: #e9415a; font-weight: bold;">立即永久</span>解锁本站全部文章</p> <img src="/images/personal/qrcode.png" style="width: 180px; margin-top: 10px; margin-bottom: 30px; border: 8px solid rgb(230, 230, 230);"></div></div></div><div class="pay-read-more-wrap" style="display:none;position:absolute;bottom:0px;z-index:9999;width:100%;margin-top:-100px;font-family:PingFangSC-Regular, sans-serif;"><div id="pay-read-more-mask" style="position: relative; height: 200px; background: -webkit-gradient(linear, 0 0%, 0 100%, from(rgba(255, 255, 255, 0)), to(rgb(255, 255, 255)));"></div> <a id="pay-read-more-btn" target="_blank" style="position: absolute; left: 50%; top: 70%; bottom: 30px; transform: translate(-50%, -50%); width: 160px; height: 36px; line-height: 36px; font-size: 15px; text-align: center; border: 1px solid rgb(222, 104, 109); color: rgb(222, 104, 109); background: rgb(255, 255, 255); cursor: pointer; border-radius: 6px;">付费阅读</a></div></div></div>
    <script src="/assets/js/cg-styles.js?v=1653305936337" defer></script><script src="/assets/js/cg-4.js?v=1653305936337" defer></script><script src="/assets/js/cg-3.js?v=1653305936337" defer></script><script src="/assets/js/cg-294.js?v=1653305936337" defer></script><script src="/assets/js/cg-5.js?v=1653305936337" defer></script><script src="/assets/js/cg-6.js?v=1653305936337" defer></script><script src="/assets/js/cg-app.js?v=1653305936337" defer></script>
  </body>
</html>
